hey i was wondering if someoen could tell me what is wrong with this regex...it does not recognize the type of line specified below i want to recognize an input line of this form blah: boo 'bee' = vast the blah: is optional and doesnt necessarily have to be present the operand before and after the equals can be of the 'anything' or consist of letters and numbers im pretty confident my reg ex is right...but for some reason it doesnt seem to recognize it... i think it may have to do with my equals sign or something. help!! here is my code below
First, are you sure this pattern fails? I mean, the code that would report a success is currently commented out. You were aware of that, right? Well the biggest problem I see is that this expression is too long and icky to be easily understood. Let's see what we can do about that. First, I note the repeated use of (\\d|\\w)+ This is somewhat silly - all digits are already word chars. (See API for Pattern.) So this is equivalent to (\\w)+ or (since you probably don't want to try to store individual letters as groups) simply \\w+ All right, that gives us
Still pretty icky. Let's break that up into groups, and put in some comments as appropriate:
Hmm, well to be honest, after doing all that I don't see any reason why this wouldn't parse "blah: boo 'bee' = vast" correctly. Are you sure it isn't working? Is there some particular pattern it isn't parsing correctly, other than "blah: boo 'bee' = vast"? One possible problem is your single quoted string expression, ('.*'). If you have two single quoted strings in your text, this expression may grab both at once. Instead try ('.*?') or ('[^']*')
"I'm not back." - Bill Harding, Twister
Joined: Mar 27, 2004
thanks for the time you took to help me out. actually i figured out the problem. it was'n recognizing this one due to another reg exp i had before it. that one which is similar to this one kept picking up what this was supposed to. thanks for your help tho!