LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help with Regular Expression (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-with-regular-expression-225519/)

subaruwrx 09-01-2004 11:07 PM

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.

Tinkster 09-01-2004 11:47 PM

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

subaruwrx 09-02-2004 01:33 AM

Quote:

Originally posted by Tinkster
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

Actually I'm using it for a program called logsurfer. The documentation that comes with it refer to the webby for regex.

subaruwrx 09-02-2004 03:47 AM

Ok I think got that it.

Now, another problem.

Code:

([^ ]*)
I would like to know if the above means that in (), I can't have a space in front of the word/character?

subaruwrx 09-04-2004 01:03 PM

Quote:

Originally posted by subaruwrx
Ok I think got that it.

Now, another problem.

Code:

([^ ]*)
I would like to know if the above means that in (), I can't have a space in front of the word/character?

bump

Dark_Helmet 09-04-2004 02:00 PM

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).

amf57 09-04-2004 07:48 PM

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.