Skip to main content
GameDev.net gamedev.net
🔒 Locked

reg expression help

Started by Kommi10 Jan 31, 2006 at 4:32 PM 4 replies 1.3k views
Original Post
Kommi10
Kommi10
I am trying to write a reg expression with the following rules: Must start with a lower case letter, can have any characters in between EXCEPT NUMBERS, must end with a lower case letter the expression I came up with is the following:
[a-z]+([^0-9]*?)[a-z]+
the problem is that "section9" will yeild "section", and "se-ction9" will yeild "se-ction". But "se1ction9" will break it down into 2 mathces, "se" and "ction". How can I change my expression so that "se1ction9" is rejected completely?
Sailorstick
Sailorstick
The ^ and the $ means the start and end of the line respectively, so that way you will only get 1 match
Telastyn
Telastyn
Quote:
Original post by Sailorstick
The ^ and the $ means the start and end of the line respectively, so that way you will only get 1 match


That's the idea.

Otherwise "se1ction9" will always result in two matches, which the OP does not want. Replacing the ^$ pair with something like [^\s][$\s] (assuming perl-esque whitespace escapes) might be a little more reasonable. The main problem with my regex is that it will not match "s", which may or may not be required, and is more complicated to fix I'd think.
Sailorstick
Sailorstick
Yes, I know that's what you meant, I was just explaining it to the OP :)
Kommi10
Kommi10
THanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.