Saturday, August 3, 2019

Regex match for HTML tag containing "on" JS trigger




I want to check if an HTML tag (potentially split across multiple lines) contains an "on" JS trigger. The actual HTML tag and the Javascript are of no consequence. For example:



    onblur="foo()"/>Other stuff


I've got most of this to work using the pattern:



    <\w+([^>])+?(on\w+)+[\s\S]+?>


However, this also matches:




    

Other stuff



I modified the original pattern to:



    <\w+([^>])+?(\s)+(on\w+)+[\s\S]+?>


but this matches only if the JS trigger keyword is preceded by 2 or more whitespace characters. A nudge in the right direction would be appreciated.


Answer



Might work <\w+(?=\s)[^>]*?\s(on\w+)[\s\S]+?>



No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...