to sanitise user input wysiwyg editor, i'm trying find following strings:
<p> </p> <p> </p> <p></p> this regular expression i'm using:
/\<p\>([nbsp\;]*|[\s]*|[ ]*)\<\/p\>/i i'm quite new regex, understand, this:
\<p\>: - matches<p>exactly, then(- matches either:[nbsp\;]*- "nbsp;" exactly, number of times|[\s]*- or whitespace character, number of times|[ ]*- or " " (a space), number of times
<\/p\>- matches</p>exactly
however, this expression matches <p>nbsp;</p> , not other two.
i have tried:
/\<p\>[nbsp\;|\s| ]*\<\/p\>/i i testing using regex101.com (first expression, second expression)
how can work?
you can't use "whole words" inside of character class, following suffice ...
~<p>(?: |\s)*</p>~i note: don't need include <space>, \s token match whitespace , don't need escape < , >, not considered special characters.
Comments
Post a Comment