Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: 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?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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 \.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: 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
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Tue Jan 06, 2009 9:59 pm   
 
Thank you.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net