正则表达式获取html输入值动态标签位置 [英] Regex get html input value dynamic tag position

查看:41
本文介绍了正则表达式获取html输入值动态标签位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当标签位置是动态的时,我对如何从输入的 html 中获取值有疑问.这是示例输入:

I've question about how to get value from input html when the tag position is dynamic. This is the example input:

<input type="text" autocomplete="" name="confirmedEmailAddress" id="emailaddress" maxlength="60" value="fname.lname@gmail.com" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">

<input type="text" autocomplete="" value="fname.lname@gmail.com" name="confirmedEmailAddress" id="emailaddress" maxlength="60" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">

这是我能够做的,但无法像第二个示例中那样检测标签值位置是否在 id 位置之前.

This is what I'm able to do, but can not detect if tag value position before id position like in the second example.

/<input(?:.*?)id=\"emailaddress\"(?:.*)value=\"([^"]+).*>/i

推荐答案

你可以试试这个:

<input.*?(?:id=\"emailaddress\".*?value=\"([^"]+)|value=\"([^"]+).*?id=\"emailaddress\")[^>]*>

演示

匹配项显示在右侧窗格中(由于某种原因在测试字符串上不可见).由于有一个 |,您必须同时检查组 1 和组 2.

The matches are shown on the right pane (not visible on test string for some reason). Since there's a |, you'll have to check both group 1 and group 2.

不过,正如许多人指出的那样,如果可以避免的话,这不应该用正则表达式来完成.

As many pointed out though, this is not something that should be done with regular expressions if you can avoid it.

这篇关于正则表达式获取html输入值动态标签位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆