It was Monday, October 06, 2003 when Trina Espinoza took the soap box, saying:
: I am running this command on a $file,
:   s/[A-Z^_]*_Leq/\n[A-Z^_]*_Leq/g;
: 
: 
: but the output I get takes the regular expression literally, so I get:
: [A-Z^_]*_Leq
: [A-Z^_]*_Leq
: [A-Z^_]*_Leq
: 
: What I would like to get is something like this:
: 
: AB_Leq
: What can I do to prevent it from taking A-Z^_]*_ literally???

The replacement portion of a regular expression can't contain a
regular expression itself, as you've noticed.  What you need to do is
capture what you've matched so you can use it in the replacement.
This is done using parens to capture.

  s/(foo)/.../g;

Now that we've captured 'foo', we can access it from the variable
called $1 in our replacement.

  s/(foo)_bar/$1/g;

If you were to capture two parts of your regular expression you'd use
$1 and $2.

  Casey West

-- 
"Heavier-than-air flying machines are impossible."
 -- Lord Kelvin, president, Royal Society, 1895.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to