in reply to Regular Expressions
The problem with what you have is that regexes are greedy by default, so that .* is going to eat up every character up to the last > on the line. To prevent this, you can use the ? modifier after the * quantifier:
Another problem with your original regex is that it would miss a tag that spanned more than one line. Fixing this problem is the purpose of the /s modifier above.s/(<body\s.*?>)/$1$newContent/is
But parsing HTML with regexes is unwise. Try something like HTML::Parser.
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular Expressions
by ww (Archbishop) on Jun 20, 2005 at 01:28 UTC | |
|
Re^2: Regular Expressions
by Anonymous Monk on Jun 19, 2005 at 22:49 UTC |