Hello, all,
I’m trying to write a RegEx that will match either four integers (“1234”) or four letters (“ABCD”), but not a mix of letters and numbers.
I’ve got this:
var FSCmask = "/^\d{4}|\w{4}$/i";
str.match(FSCmask);
But it’s always stating that the input is incorrect regardless of what I enter (“1234”, “ABCD”, “A2C4”). What am I missing?
V/r,
parenthesizes
/^(\d{4}|\w{4})$/i
Keep in mind that this will match ____ and still permits AD09, as \w includes _ and 0-9. If you DO NOT want AD09, you should use [a-z]{4}
“Parenthesizes”??
So, just adding parenthesis to the expression should fix this? (Banging head into desk)
I’ll give that a shot. Thanks!
[quote=“cpradio, post:2, topic:190098”]
If you DO NOT want AD09, you should use [a-z]{4}
[/quote]D’oh! Thanks, again!
V/r,
Yes, as the | operator applies inside parenthesizes.
WolfShade:
D’oh! Thanks, again!
Yup… that nailed it. Thanks!
1 Like
tevko
May 18, 2015, 7:07pm
6
I use regex101.com (but that is just my personal preference) I also have the book Regular Expressions Pocket Reference by O’Reilly and I highly recommend it. I use it weekly.
RegExr will load, but that’s all it will do. Work network is super-paranoid (civil service). But, thanks for the suggestion.
V/r,
Regex101.com works, here! Very nice. Thanks!
1 Like
system
Closed
August 18, 2015, 3:23am
10
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.