Regular expression to identify text box in HTML form

2

Situation

Give yourself a HTML page where you will find a form containing two text boxes, one for the name and one for the email. Then there was the need, to do some tests on Android, to get only a snippet of the code and play in a list, but I tried in some ways to create a regular expression to retrieve that code part but I did not succeed. The org.apache.http.legacy library is used to obtain source code where no barrier was found in reading the following code.

Code

<!DOCTYPE html>
    <html>
       <head>
       </head>
       <body>
          <form>
             <label for="nome">Nome</label>
             <input type="text" name="nome" id="nome"/><br><br>
             <label for="email">email</label>
             <input type="text" name="email" id="email"/><br><br>
             <input type="submit" value="Enviar">
          </form>
       </body>
    </html>

Doubt

I would like to use the regex to identify exactly the beginning and end of each input , being <input and /> , so for this HTML would result for example in two items:

<input type="text" name="nome" id="male"/>
<input type="text" name="nome" id="male"/>

After the ID, I want to play each input within a array (But that part is quiet). Could someone help me with that expression? Hugs!

Note: The expression in this case would be language independent. If I am going to use such a method or such language (java, c #, javascript), then I will use the% required% for libs .

Hugs! =)

    
asked by anonymous 28.08.2016 / 21:34

1 answer

1

You can use the following expression: <\s* input [^>]+ >/xg

<

Matches "<" literally

\S

will match any character whitespace [\ r \ n \ t \ f].

*

between zero and unlimited times, as many times as possible, going around as needed [greedy].

input

house with the word leteralmente (case sensitive).

[^>]+

match a single character not present in the list.

+

between one and unlimited times, as many times as possible, turning around as needed [greedy].

>

Unique character in the list, ">" literal (case sensitive).

>

matches ">" literally.

/g

global modifier, not for the first occurrence.

/x

Extended modifier ignores whitespace and comments.

Test and Explanation: Regex_input_tag

More about Regex: Aurélio Regex

    
29.08.2016 / 01:40