Jump to content
Sign in to follow this  
PartyPooper

Regular Expressions

Recommended Posts

PartyPooper

Hi all, I know that there are various implementations of RegEx's floating around and was just wondering if the \w and \W matching characters are suppose to be equivalent to [a-zA-Z0-9_] and [^a-zA-Z0-9_] respectively (like in python) or just [a-zA-Z_] and [^a-zA-Z_] ?

Cheers

Share this post


Link to post
Share on other sites
LxP

The help file suggests that \w matches A-Z, a-z and _ only.

Edit: Python is weird. B)

Edited by LxP

Share this post


Link to post
Share on other sites
PartyPooper

Yeah, figured that after the expression failed. Was trying to limit the characters to valid filename ones and have got [^a-zA-Z0-9_-]. Just gotta figure out how to allow a space character now.

P.S. I hate regex's - confuse the hell outta me everytime B)

Share this post


Link to post
Share on other sites
PartyPooper

Well that was easier than I thought - just changed it to [^ a-zA-Z0-9_-] and it seems to work B)

Share this post


Link to post
Share on other sites
LxP

I'm not sure that the hyphen will be matched (which seems to be what you want). Try escaping it:

[^ a-zA-Z0-9_\-]

Share this post


Link to post
Share on other sites
PartyPooper

It matched ok here as is. The space didn't when I added it to the end but it did when I moved it to the beginning of the expression. Maybe it has something to do with precedence?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.