|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Tue Jan 06, 2009 8:53 pm
Grr at Regex again |
Well, school has me caught up and so I've made little progress on my scripts as I'd rather play the game with what time I have. However, I'm setting up a quick little script for reading, problem is with the regex:
Code: |
read ([\w'- ]+)page (\d+)
|
When I try to test it, I get an out of order character class (145) error. I have absolutely no clue what this is or means, I rearrange the -, ', and ' ' but I only get different numbers between the (). What am I doing wrong? How do I avoid this in the future? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Jan 06, 2009 8:55 pm |
- is a special character in classes, so you can do things like [a-z]. The "out of order class" is because it looks like you're doing ['- ], when a space actually comes before an apostrophe, so it doesn't know what to do. If you literally meant a hyphen to be part of the class, you need to escape it with \.
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Jan 06, 2009 9:32 pm |
You may also put the hyphen last, the regex engine will then see that it isn't providing a range of characters for the class and treat the hyphen as a literal. [\w' -] would be a correct usage, or as Fang said escpae it [\w'\- ]
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Tue Jan 06, 2009 9:59 pm |
Thank you.
|
|
|
|
|
|