Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 04-01-2009, 12:05 PM   #16
Registered: Dec 2006
Posts: 97

Original Poster
Rep: Reputation: 15

Originally Posted by Robhogg View Post
I know what you mean - I often refer to these patterns as an explosion in a punctuation factory. They are called regular expressions, and consist of literal characters and metacharacters. The pattern means:
!             Delimiter beginning search pattern
\(<h1>\)      Group 1: literal <h1>
\(<a[^>]*>\)  Group 2: <a then 0 or more characters that are not >'s, then >
\([^<]*\)     Group 3: Any number of characters that are not <'s
\(</a>\)      Group 4: literal </a>
\(</h1>\)     Group 5: literal </h1>
!             End of search pattern, beginning of replace pattern
\1            Replay group 1
\3            Replay group 3
\5            Replay group 5
!             End of replace pattern
Some stuff on sed and regular expressions from the Linux documentation project.

The reason you got the error message is that you used single quotes - '...' - rather than backticks -`...` around the ls command in the first line - very easy to do. Backticks are on the key to the left of the 1 on a US/UK keyboard, but I would tend to use $(ls *.html) - the $(...) does the same thing as the backticks, but is a lot easier to read.

Edited to add: slight warning about the documentation on regular expressions - there are different forms. For instance, in the link above, it tells you prentheses -- ( ) -- enclose a group. However, in the sed version, escaped parentheses - \( \) - are used.
Rob, I have to thank you again for the explanation above, it all makes sense now. Thank you.
Old 04-02-2009, 07:07 AM   #17
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,396

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
Just a small fyi; each lang that processes 'regexes' uses an internal 'regex engine'. However, each regex engine tends to be different to other regex engines, to a larger or smaller degree.
See for example
IOW, regex 'incantations' may or may not(!) be transferable... YHBW...
Old 04-02-2009, 02:32 PM   #18
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Originally Posted by shahgols View Post
Wow, thank you so much Rob for helping me learn this stuff.
No problem - "glad to be of service!", as a Sirius Cybernetics Corporation door might say


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
when to quote or not to quote variable names - mktemp problem glinux Linux - Newbie 3 02-20-2009 04:37 PM
Price quote... jsm Linux - General 2 11-08-2006 02:20 PM
Boot Quote? liquidrabbit Slackware 3 04-10-2006 05:37 PM
Quote 1 gb to 1 user? itz2000 Linux - Newbie 5 02-19-2006 02:30 PM
quote tundra General 2 09-21-2002 05:58 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:38 AM.

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