in reply to Regex help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex help
by ww (Archbishop) on Jul 25, 2009 at 19:47 UTC | |
I don't think so. Did you test that notion? See characters in a character-class in "Mastering Regular Expressions" and Friedl's explanation that character-class-metacharacters are NOT the same as metacharacters outside a character class (pp 9-10). He also alludes to the differences elsewhere in the text. Very little is interpolated inside a character class (with the obvious exceptions of the likes of "-" or an initial "^" negation). However, returning to OP's conundrum: it does NOT appear to be quite as stated. Rather, it appears to me that "Hello there0" matches his posted regex, while removing the preceding "\" before the "$" causes it to fail. Now, the distraction of a very nice summer day (one of very few, thusfar) discourages me from feeling that the following is an adequate answer, but /me thinks "hello there0" passes his regex because his regex does not include decimal digits (see my line 14). However, I must admit, I don't understand why, when using my line 11 rather than 14, the output is as it is: "hello there0" is not okay, but "hello there$ now" is. Brighter minds; wiser heads, pray edify! Update: graff has. See his correct analysis below and everybody's above. Apologies to everybody and to OP. Balance of this post allowed to stand for whatever value (as an object lesson in incomplete testing/analysis) it may have.
| [reply] [d/l] [select] |
by graff (Chancellor) on Jul 25, 2009 at 21:17 UTC | |
The OP figured out that putting backslash in front of "$" would make the regex work as intended, but did not understand why, and everybody gave the correct explanation: without the backslash, you get an interpolation of the variable "$%", and its value turns out to be zero. Try this (NB: this uses bash shell style quoting): You'll see a zero in both lines of output. | [reply] [d/l] |