On Fri, Jun 5, 2009 at 4:25 AM, dorkie dork from
dorktown<[email protected]> wrote:
> My RegExp is being greedy. There are two matches. The regexp is grabbing the
> first span all the way to the last span. How do I prevent it from being
> greedy?
>
> Given this string:
>
> Vestibulum <span style="text-decoration: underline;">aliquet</span>
> <em>leo</em> in <b>enim</b> <span style="text-decoration:
> line-through;">viverra</span> id lacinia arcu eleifend.
[...]
Normally if you want to make ".*" non-greedy, you append a "?" to it.
Here's something I did with your source string:
var s:String = 'Vestibulum <span style="text-decoration:
underline; font:bold">aliquet</span> <em>leo</em> in <b>enim</b> <span
style="text-decoration: line-through;">viverra</span> id
lacinia arcu eleifend.';
s =
s.replace(/(<span[^>]+style="[^"]*)text-decoration:\s*underline;?([^"]*"[^>]*>)(.*?)(<\/span>)/g,
"$1$2<u>$3</u>$4");
trace(s);
I've made it more strict in terms of how it matches stuff. But you
should be able to modify your original regexp just by appending a "?"
to the ".*".
Manish