Regular Expressions 101

Community Patterns

Regex to find begin and end of a HTML tag with a certain class

-1

Regular Expression
PCRE (PHP <7.3)

/
<([A-Za-z]{1,7}) .*class='([a-zA-Z0-9_ ]{0,})searchedclass[ '].*>.*<\/\1.*>
/
iUs

Description

The regex finds for example the <td class='searchedclass'>random text</td> sequence, if ohne single quotes ar used. The td itself may vary (td, div, span, p and so on), the provided class ist the item searched vor.

Submitted by xm318 - 8 years ago