How to get only specific <input> HTML tag wi

2019-08-22 23:25发布

I've ask how to handle inconsistent HTML tag attribute position here: Regex get html input value dynamic tag position. I want to ask another question how to match only specific that the string separate by SPACE, not by break line. This is the string example:

<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="joko145" name="confirmedUsername" id="username" maxlength="60" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">

I've tried this:

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

to get the value, but instead it return the username value, it return emailaddress value. The first return array (full text detected by regex) like this:

<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="joko145" name="confirmedUsername" id="username" maxlength="60" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">

It detect all the from the string, not specific that I want like below:

<input type="text" autocomplete="" value="joko145" name="confirmedUsername" id="username" maxlength="60" class="txt-box  txtbox-m "  aria-describedby="" aria-required="true" disabled="disabled">

It happened only when HTML tag separate by SPACE, not by break line. How to get only the username when it separate by SPACE? Thanks.

标签: regex match
0条回答
登录 后发表回答