CodeIgniter Forums
Regex help - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Libraries & Helpers (
+--- Thread: Regex help (/thread-26170.html)

Regex help - El Forum - 01-07-2010

Can someone please help me, my regular expression is not doing what I need it to do.
What I need is 4 characters, a-z uppercase or lowercase, followed by at least 1 digit to inifinite amount of digits. Current I have:

It's weird, test cases I've tried:

ssss2 - Succeed
ssss2222 - Succeed
s2 - Fail
sss2 - Fail
s2323424 - Succeed

Seems its treating \w to work even if digits are supplied, can anyone help me? Thank you.

Regex help - El Forum - 01-07-2010

instead of \w use [A-Za-z]

Regex help - El Forum - 01-07-2010

I thought I had tried that, apparently there is a big difference in putting A-Za-z inside of () brackets compared to [] brackets. Thanks for the help.

Regex help - El Forum - 01-07-2010

[eluser]Jamie Rumbelow[/eluser]
Just for clarification gigas, () tries to match everything it's contents. Square brackets [] specify a range of characters. If you don't know the difference, it can get pretty confusing!


Regex help - El Forum - 01-07-2010

[eluser]Sean Gates[/eluser]
For reference in this thread: if you are using a mac there is a great tool called RegExhibit. Works beautifully to quickly test and edit you regular expressions.

Regex help - El Forum - 01-09-2010

[eluser]Yorick Peterse[/eluser]
Untested, but should do the trick: