soycharliente Posted March 25, 2008 Share Posted March 25, 2008 From looking at a tutorial ... A dot (.) means any character so long as it's not a newline character. [] are used to define character classes to apply rules to or for allowing. So, what does this mean? ([-+.])* Does that mean: Zero or more of A. either of those 3 literal characters B. either a - or + or any other character so long as it's not a newline character Common sense would tell me A is right, but I just want to be sure. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 25, 2008 Share Posted March 25, 2008 well, first, a '-' is also a special character, so you would need to escape it with a '\' but '-' and '+' are included with '.', so that would be redundant. you should never need a . inside [] Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 25, 2008 Share Posted March 25, 2008 a . inside of a character class is literally a . Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 25, 2008 Share Posted March 25, 2008 really? and i learn yet something else new! Quote Link to comment Share on other sites More sharing options...
toplay Posted March 25, 2008 Share Posted March 25, 2008 well, first, a '-' is also a special character, so you would need to escape it with a '\' but '-' and '+' are included with '.', so that would be redundant. you should never need a . inside [] A dash ('-') doesn't need to be escaped ('\') inside a character class when it's at the beginning or end. Also, discomatt is correct. It's well worth buying this regex software: http://www.regexbuddy.com and this book - Mastering regular expressions: http://www.oreilly.com/catalog/regex3/ Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 25, 2008 Share Posted March 25, 2008 looks like i need to brush up on my character classes Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 25, 2008 Author Share Posted March 25, 2008 So I was right. Option A is correct? Also, I noticed that somehow I might have posted this in the tutorial section and it got moved. I have no idea how I got in there, but thanks for moving this. Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 25, 2008 Author Share Posted March 25, 2008 I can't find anything that says the comma is a special character. So what does this mean? ([,]|[,])\s* Quote Link to comment Share on other sites More sharing options...
effigy Posted March 25, 2008 Share Posted March 25, 2008 So, what does this mean? ([-+.])* The others have already explained this, but what is the context of this pattern? ([-+.]*) would likely be better, but, again, this depends on the context. I can't find anything that says the comma is a special character. So what does this mean? ([,]|[,])\s* It's not--that's a confusing pattern. It should be ,\s* unless you really need to capture the comma. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 25, 2008 Share Posted March 25, 2008 Grab the regexbuddy free trial.. it's a great piece of software. You will become addicted to it though, so be ready to shell out a couple bucks to purchase It explains every detail of your expression in plain english http://www.softpedia.com/get/Programming/Other-Programming-Files/RegexBuddy.shtml Your regex does the following: match either a comma or a comma exactly once, capture it in group 1 match a whitepace character (space, tab, linebreak, ect) 0 or more times, as many times as possible, giving back as needed Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 25, 2008 Author Share Posted March 25, 2008 ... but what is the context of this pattern? Someone gave me this email regex a while ago. /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(([,]|[,])\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$/ It works better than any other pattern I've ever seen. I've tried others in regex testers online and can make each of them fail with a simple address. I've been using it for a while and never bothered to try and figure out the pattern. Just sat down today and tried to work through it, but as you can see, getting confused because of things like "looking for a comma or a comma". Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 25, 2008 Share Posted March 25, 2008 Grab the trail of regexbuddy. Paste the expression into it. View the 'Create' tab. Quote Link to comment Share on other sites More sharing options...
effigy Posted March 25, 2008 Share Posted March 25, 2008 Other options include: 1. Use Perl's YAPE::Regex::Explain. 2. Use the /x modifier and add line breaks and comments to the pattern. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.