Need help for Regex

E

Evgeny Zoldin

Hi All,

I want to capture the argument of some javascript function call in HTML
source code, namely HTML-Page contains

<script....>
func ( 'something1\'something2' );
</script...>

or

<script....>
func ( "something1\"something2" );
</script...>

I try to capture whole argument of the function call by the following:

string s = html_source;
Regex re = new Regex(@"(?<a>'.*?(?!<\)')"); // or new
Regex("(?<a>\".*?(?!<\\\\)\")");
Match m = re.Match(s);
Group g = m.Groups["a"];
string r = g.Value;

and here r is <'something1\'> but not <'something1\'something2'> as I want.
What's wrong?

Thanx
 
N

Niki Estner

Evgeny Zoldin said:
Hi All,

I want to capture the argument of some javascript function call in HTML
source code, namely HTML-Page contains

<script....>
func ( 'something1\'something2' );
</script...>

or

<script....>
func ( "something1\"something2" );
</script...>

I try to capture whole argument of the function call by the following:

string s = html_source;
Regex re = new Regex(@"(?<a>'.*?(?!<\)')"); // or new
Regex("(?<a>\".*?(?!<\\\\)\")");
Match m = re.Match(s);
Group g = m.Groups["a"];
string r = g.Value;

and here r is <'something1\'> but not <'something1\'something2'> as I
want.
What's wrong?

Maybe that should be "...(?<!\\)..." instead of "...(?!<\\)..."?

Niki

PS: Please don't Multi-Post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top