LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-02-2004, 12:07 AM   #1
subaruwrx
Member
 
Registered: Mar 2004
Distribution: Ubuntu Feisty
Posts: 641

Rep: Reputation: 30
Question 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.

Last edited by subaruwrx; 09-02-2004 at 12:13 AM.
 
Old 09-02-2004, 12:47 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
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
 
Old 09-02-2004, 02:33 AM   #3
subaruwrx
Member
 
Registered: Mar 2004
Distribution: Ubuntu Feisty
Posts: 641

Original Poster
Rep: Reputation: 30
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.
 
Old 09-02-2004, 04:47 AM   #4
subaruwrx
Member
 
Registered: Mar 2004
Distribution: Ubuntu Feisty
Posts: 641

Original Poster
Rep: Reputation: 30
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?
 
Old 09-04-2004, 02:03 PM   #5
subaruwrx
Member
 
Registered: Mar 2004
Distribution: Ubuntu Feisty
Posts: 641

Original Poster
Rep: Reputation: 30
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
 
Old 09-04-2004, 03:00 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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).

Last edited by Dark_Helmet; 09-04-2004 at 03:04 PM.
 
Old 09-04-2004, 08:48 PM   #7
amf57
LQ Newbie
 
Registered: Feb 2003
Posts: 22

Rep: Reputation: 15
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/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with regular expression aecaudel Programming 6 11-04-2005 06:28 AM
Anyone know regular expression? ahhua Linux - Software 1 12-04-2003 09:13 AM
Regular Expression Help WeNdeL Linux - General 1 08-14-2003 11:08 AM
Regular Expression slizadel Programming 4 07-28-2003 06:16 AM
regular expression gumby Programming 3 07-15-2003 01:13 PM


All times are GMT -5. The time now is 06:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration