How do I write a regular expression?

  • 0
    The page has fields with value = there are several of them, one of them is responsible for mail, I need to parse the page with a get request and pull out exactly the mail, how to do this, I tried many options, it still does not work to cut off the code after the mail
    </th><td>
    			<input type="text" name="email" id="email" class="required email" value="[email protected]" />
    		</td></tr>
    		<tr><th>
    			<label for="createdate">Дата покупки</label>
    JavaScript Anonymous, Jul 22, 2019

  • 2 Answers
  • 0
    Don't suffer with regulars. Yuzai DOM:

    const html = `<td>
    <input type="text" name="email" id="email" class="required email" value="[email protected]" />
    </td>`

    const template = document.createElement('template')
    template.innerHTML = html
    console.log(template.content.querySelector('input[name="email"]').value) // [email protected]
    Anonymous

  • 0
    If you need regulars - this is how you can

    let m= document.body.innerHTML.match(/(?=[^>]*name="email")<input[^>]+value="([^"]+)"/is);
    console.log(m[1]);


    Regular of 2 halves. The second one defines an element and picks out its value, the first one checks that the name of this element is correct. The expectation is that the quotes will always be double.

    Through the House, of course, is better. You don't have to put quotes around.
    Isabella Skinner

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!