December 2016
Beginner
48 pages
1h 12m
English
© Jörg Krause 2017
Jörg Krause, Introducing Regular Expressions, 10.1007/978-1-4842-2508-0_4
Jörg Krause1
(1)Berlin, Germany
You have to do some tasks again and again in your life as a developer. This chapter contains several useful examples.
The expressions in this section are dedicated to web and network environments.
This is how you look for an HTML tag with the fixed name DIV:
/<DIV\b[ˆ>]*>(.*?)<\/DIV>/iAnd this expression looks for any tag:
/<([A-Z][A-Z0-9]*)\b[ˆ>]*>(.*?)<\/\1>/iOnce again, I’m using a \1 reference on the first hit to find the matching closing tag.
1 var patt = /<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)<\/\1>/i;2 var html = "Ww want write <b>bold</b> and <i>italic</i> here";3 console.log(patt.exec(html)); ...
Read now
Unlock full access