Need help with Regular Expression
Hi, I refer to this excellent http://www-aig.jpl.nasa.gov/public/m...html#SEC6]site on regex.
However, I am still unsure what the backslash character, \, does. I know one of its function is to get rid of the special meaning of a character. Thanks. |
Are you referring to programming with the RegEx libraries,
or using the Regular Expressions as they are being used in tools as egrep, sed and awk? If it's the latter, that tutorial is not for you, and you needn't worry about bullet 3 and a bit of 2 on that page. Cheers, Tink |
Quote:
|
Ok I think got that it.
Now, another problem. Code:
([^ ]*) |
Quote:
|
Ok, the [^ ] tells the expression to match against any character other than a space. The caret ( ^ ) at the beginning of the set, inverts how the set matches. So instead of matching what is listed, it matches anything that is not listed. The asterisk ( * ) specified to match 0 or more repeats of the previous set of characters. So, if there is a contiguous section of non-space characters, this pattern will match it. The parentheses are used to "store" the matched text. Usually, they are used in expressions to find the meaningful text in a line, and then replace the entire line leaving only the meaningful bits behind. Parentheses are also used to construct complex pattern matching by grouping combinations of small, primitive regular expressions.
EDIT: Sorry, I got a little carried away. To directly answer your question, no, the expression you give will not allow a space before a given word is matched. In this case, it looks as though the parentheses are used in their "storage" role, and are not literal parentheses (you would need to escape them with a backslash to do that). |
Unfortunately you have to realize that regular expressions are sometimes quite different from metacharactors.
Where as ^ generally means "at the beginning of the line" when it is used in brackets it is as Dark_helmet said. It means the inverse (just like -v in grep). You may want to download ant install txt2regex application at http://freshmeat.net/projects/txt2regex/ |
All times are GMT -5. The time now is 06:40 AM. |