[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: backrefs in regexps?
From: |
Tim Nelson |
Subject: |
Re: backrefs in regexps? |
Date: |
Tue, 19 Oct 2004 14:01:00 +1000 (EST) |
On Tue, 19 Oct 2004, martin f krafft wrote:
Hi all, I am new to cfengine and thus, this may be a really dumb
question. However, I went through the docs and I could not find the
solution, honestly.
I am trying to use editfiles/ReplaceAll and backreference into the
search pattern, conceptually like so:
ReplaceAll "foo(.*)bar" With "bar$1foo"
However, the $1 is replaced literally. Is there a way to do what
I want/need?
Looking at this and your other question, you need to carefully
learn the differences between the three different types of Regex. They
are:
- Basic (POSIX) Regex
- Extended (POSIX) Regex
- Perl Regex
Basic Regex is the one used by most Unix utilities such as grep.
Extended is supported by most of the same utilities (grep -E, or egrep).
Perl regex is only supported by some tools (eg. Perl, the pcre library,
PHP, and some others). You'll notice that the cfengine Reference manual
says "The regular expression matching functions are POSIX extended regular
expressions". For more information:
http://en.wikipedia.org/wiki/Regular_expression
Anyway, to come back to your problem...
In this e-mail, you may find that it works if you use \1 instead
of $1. If not, you'll need to do some more reading.
In your other e-mail, you'll find that \s doesn't exist in eregex.
You could use [[:space:]] (elegant but long-winded) or [ \n\t] (and maybe
\r too).
Hope this helps...
--
Tim Nelson
Server Administrator
WebAlive Technologies Global
Level 1 Innovation Building, Digital Harbour
1010 LaTrobe Street
Docklands, Melbourne,
Vic, 3008
Phone: +61 3 9934 0812
Fax: +61 3 9934 0899
E-mail: tim.nelson@webalive.biz
http://www.webalive.biz/