开发者

How to write a PCRE regular expression to find a string with different content?

开发者 https://www.devze.com 2023-02-04 03:12 出处:网络
This may be a simple one but I can\'t seem to find the answer to it. I have a string in a HTML file that I am looking for:

This may be a simple one but I can't seem to find the answer to it.

I have a string in a HTML file that I am looking for:

<div class="button" onclick="docu开发者_运维百科ment.$name.submit(); return false\">Save</div>

where $name is is generated by code, so can be anything.

I need to write a PCRE regular expression that will find this string in the file but disregard the $name section of the string.

I have tried this :

/<div class=\"button\" document.(.+?).submit\(\); return false\">Save<\/div>/

It will return the group that equals to what is in $name. but not define it as a match, which is what I need.


The following should work:

/<div class="button" onclick="document\.(.+?)\.submit\(\); return false">Save<\/div>/

Most likely your problem was that you forgot to escape the parenthesis after submit(), so it tried to match submit;.


Try this

@<div class="button" onclick="document.(.*?).submit\(\); return false">Save</div>@
0

精彩评论

暂无评论...
验证码 换一张
取 消