I need an regular expression for RR-1000 i.e First two digits must be alphabets and it must be followed by an '-'(hyphen) then there must be four numbers .The total length should not be greater than 7 digits.
Asked
Active
Viewed 441 times
-1
-
2digits != alphabets. Anyway, any attempts? – Jerry May 12 '14 at 16:55
1 Answers
1

hjpotter92
- 78,589
- 36
- 144
- 183
-
1You don't even need the parentheses or brackets; `[A-z]{2}-\d{4}` should work fine. – Andrew May 12 '14 at 16:59
-
@AndrewArnold A few languages define `-` differently. Since I primarily work in Lua, the `-` means a lazy match. And hence, my practice of enclosing it as `[-]` – hjpotter92 May 12 '14 at 17:01
-
True, it depends on language. My answer is valid in Javascript, at the very least. – Andrew May 12 '14 at 17:01
-
-
1@Jerry http://www.lua.org/pil/20.2.html Search the following on the page: "Patterns in Lua offer four modifiers" – hjpotter92 May 12 '14 at 17:04
-
I wouldn't call it regex, but more like a Lua expression if you ask me xP And if you did write a Lua pattern, you'd have to use `%a%a%-%d%d%d%d` instead of what you have used above. – Jerry May 12 '14 at 17:09
-
@Jerry of course; but I've been writing lua patterns for so long that `[-]` is just muscle memory :P – hjpotter92 May 12 '14 at 17:15
-
2Lol, ok. Though your regex isn't entirely correct. See [this](http://stackoverflow.com/a/18661919/1578604). – Jerry May 12 '14 at 17:21