|
-
Dec 29th, 2009, 11:44 PM
#1
Thread Starter
Frenzied Member
Regex Help
I should make time to learn some regex, as in cases like this http://regexlib.com/ does not help that much.
Someone can give me the regex to matc a string, of which the last character will always be a number from 1 to 6?
yui-t1 - no match
yui-t1 - match
yui-t2 - match
yui-t3 - match
yui-t4 - match
yui-t5 - match
yui-t6 - match
yui-t7 - no match
-
Dec 30th, 2009, 02:39 AM
#2
Re: Regex Help
If that's the only rule you care about, then:
.* means "any character, as many times as you want."
[1-6] defines any number between 1 and 6 (inclusive)
{1} specifies that there should be just 1 of the number between 1 and 6
$ denotes the end of the line
So all together this means, "any number of any character, followed by a single number 1-6, and then the line ends."
You can of course get more specific about the first part of the pattern, if you'd like.
-
Dec 30th, 2009, 11:48 AM
#3
Re: Regex Help
make sure you realize that the * operator in regular expressions also allows zero characters to be found; a better description might be zero or more of any character, whereas the + operator requires that one or more of any character is found. you could switch them around if you need a string to precede the number.
and, like Samba mentioned, you can get much more specific about the formatting of the first part of that string (requiring the 'yui' [or any other sequence of 3 alphabet characters], requiring the dash, requiring a t [or any single alphabet character] to precede the number, etc). you can be as specific or as general as you want to be!
finally, I would suggest this website if you want to first learn about regular expressions. the regular expression library isn't really all that helpful for learning; regular expressions are an incredibly difficult thing to get your head around sometimes ;)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|