LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   RegExp help (https://www.linuxquestions.org/questions/linux-newbie-8/regexp-help-705075/)

HarryBoy 02-16-2009 10:19 AM

RegExp help
 
I have a regular expression that compares a string. It is as follows:
var string = new RegExp( ' [ ' + leters + ' ][ ' + letters + ' 0-9]+ ' );

This is used to check if a string starts with a letter and then letters or numbers.

how do I modify this so it can start with letters OR numbers, instead of just letters?

Thanks

theYinYeti 02-16-2009 10:31 AM

First, I suppose it is Javascript language.
Next, I find very strange the way you write this regex, and with way too many spaces; programming leaves little room for approximation…
Your example would have been simpler as “new Regex('[A-Z][A-Z0-9]+','i')” and then it would still have been false, missing the extra “^” at the start of the regex to match only at the start of the string.

As for the answer, something like this should do: “new Regex('^[A-Z0-9]{2,}','i')”.

Yves.


All times are GMT -5. The time now is 11:01 PM.