Log in

View Full Version : Regex First Character Is Different Than



Master_script_maker
05-15-2008, 07:45 PM
Hi, I've been trying for a long time to do this, but to no avail. I have a regex ,/[^!]([a-zA-Z0-9]{1,15})/, that sort of works, but not exactly. I would like to make sure the first character is not an exclamation point, but is a number/letter, sort of like /[!]{0}([a-zA-Z0-9]{1,15})/, which unfortunately doesn't work. Any help would be highly appreciated.

boogyman
05-15-2008, 08:13 PM
/^[A-z0-9]{1,15}$/
must contain at least 1 character and have no more than 15 characters
must only contain case-insensitive alphabet letters or digits

the reason yours didn't work was because you checked for the non existence of the carot, however you didnt specify the beginning or the end of the string... by doing a carot at the beginning you are starting the string and a dollar sign at the end you are ending the string... so the only allowable input is what you are checking for...

a carot symbol anywhere else but the first character of the expression means the following statement must NOT exist

[^!] states the next character cannot be an exclamation point... however that could be confused with....
next character is either a carot or an exclamation point,

what you could have done was /^(^!) or /^^[!] the latter of which could also be confusing

Master_script_maker
05-15-2008, 08:32 PM
the problem with that is i am not matching it at the beginning of the string. e.g ";!ignore match;"

Master_script_maker
05-16-2008, 11:08 AM
does anyone know how to do this?

boogyman
05-16-2008, 01:05 PM
how do you determine where to start??

you have two options..
1. you can put in some checks to do the first part, then check your "string"
2. only pass in the part of the string that you wish to check against an exclamation point


on a side note, if you dont want there to be an exclamation point anywhere in the entire string you can use


/(^!)/