Title |
Test
Find
Pattern Title
|
Expression |
<(.*?)> |
Description |
Can anyone help me with this problem? I want X to give me the correct index of >. For example if this is my code:
var MsgString="<button onclick='4>5?a():b();'>";
X=MsgString.search(/>/ig);
X will give me 18 instead of 30. How can I get it to ignore > that are within quotes? Please help. I would really appreciate it if anybody could give me some advice. Thanks so much.
-Logan |
Matches |
<test a> |
Non-Matches |
none |
Author |
Rating:
Not yet rated.
Logan Tran
|
Source |
|
Your Rating |
|
Title: Try this
Name: Lars Echterhoff
Date: 8/13/2005 12:21:21 PM
Comment:
<(.*?\W)>
OK, its not as clean as it can be but a possible solution.
This matches everything inside your tag and finishes matching with an > after anything else than charcters oder numbers (just boundaries). Just try.
Title: Possible solution...
Name: Alex Forencich
Date: 8/12/2005 6:00:27 PM
Comment:
Can't you just use lastIndexOf()?
Title: Coder
Name: Chad
Date: 2/3/2004 7:11:08 AM
Comment:
Unfortunately what you want to do is a 'negative' match which regex doesnt really do well except for very simple featureless negative matching.
Your best bet is to use a character by character parser which walks through the string switching on a flag when is comes across a quote and then ignores '>' until it finds the closing quote.