Even though I don't expect to come across newline characters, your suggestion of using \z and /s is a good one. I definitely only want strings of 50 characters or less -- no matter what characters they are -- to match.
Unfortunately, I don't see a way around using the dreaded .* before the actual pattern I'm looking for. Otherwise it will only match when the pattern occurs at the beginning of the string, since (?=^.{0,50}\z) is a zero-width assertion that's anchored to the start of the string. My original version had the ^ anchor inside the lookahead, like yours, but since it seemed that I had to use .* in either case, I decided to move it outside of the lookahead. However, it's probably clearer to leave it inside.
Also, to clarify my question further, I actually need a matching regex and not a substitution regex. Maybe this is more like golf than I originally realized ...
-jehuni
In reply to Re: validating string length with a regular expression
by jehuni
in thread validating string length with a regular expression
by jehuni
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |