I am really new to Regex and still, I am trying to understand the way it works. I am trying to develop a regex to capture name and value from input tag in HTML.
<input type='hidden' name='student' value='9208'>
My idea is to extract the value related to name(student) and the value(9208). I have developed the following regex based on an earlier answer in the stakcoverflow for a previous question.
/<(input)(?:\s+type=([\'"]?)(?<type>[^\'"]*?)\2\s*)?(?:\s+name=([\'"]?)(?<name>[^\'"]*?)\4\s*)?(?:\s+value=([\'"]?)(?<value>[^\'"]*?)\4\s*)?>/m
Above regex is working properly with input like
<input type='hidden' name='student' value='9208'>
But, it is not capturing string if there is no single quotation marks or double quotation marks around the value corresponding with the value attribute (value='9208') eg-
<input type='hidden' name='student' value=9208>
In the above case, it didn't give any matches. Can someone help me to fix the above regex? Thank you