I want to use a regular expression to match the input, select, and textarea tags in html code. other tags are not required. My statement is as follows: {code ...} however, I found that what I wrote can match all the labels. I know that [input | textarea | select] is wrong, but I don't... I want to use a regular expression to match the input, select, and textarea tags in html code. other tags are not required.
My statement is as follows:
$text = "
";$pattern="/<.*?[input|textarea|select].*?>/i";preg_match($pattern1,$text,$matches);var_dump($matches);
But I found that what I wrote can match all the tags. I know that[input|textarea|select]
I am wrong, but I don't know how to modify it or how to write it in a simpler way.
Reply content:
I want to use a regular expression to match the input, select, and textarea tags in html code. other tags are not required.
My statement is as follows:
$text = "";$pattern="/<.*?[input|textarea|select].*?>/i";preg_match($pattern1,$text,$matches);var_dump($matches);
But I found that what I wrote can match all the tags. I know that[input|textarea|select]
I am wrong, but I don't know how to modify it or how to write it in a simpler way.
[] Means to match a specified character, not a string
(String1 | string2) is to match multiple strings
(?! String1) matchNonString
Correct:
/<.*?(input|textarea|select).*?>/is
For example
[A-zA-z0-9 _ \-] indicates matching ~ Z ~ Z 0 ~ 9 _-these characters (only one character) [a-zA-z0-9 _ \-] * indicates matching ~ Z ~ Z 0 ~ 9 _-only strings of these characters (note *) (input | textarea | select) indicates matching these strings