if you got the input:
'<p class="drug-subtitle"><b>Generic Name:</b> albuterol inhalation (al BYOO ter all)<br><b>Brand Names:</b> <i>Accuneb, ProAir HFA, Proventil, Proventil HFA, ReliOn Ventolin HFA, Ventolin HFA</i></p>'
and you want to check if :
<p class="drug-subtitle"> .. some items here .. </p>
exists in your input, the regex to be used is:
\<p\sclass=\"drug-subtitle\"[^>]*>(.*?)\<\/p\>
description:
\< matches the character < literally
p matches the character p literally (case sensitive)
\s match any white space character [\r\n\t\f ]
class= matches the characters class= literally (case sensitive)
\" matches the character " literally
drug-subtitle matches the characters drug-subtitle literally (case sensitive)
\" matches the character " literally
[^>]* match a single character not present in the list below
Quantifier: Between zero and unlimited times, as many times as possible,
giving back as needed.
> a single character in the list > literally (case sensitive)
> matches the character > literally
1st Capturing group (.*?)
.*? matches any character (except newline)
Quantifier: Between zero and unlimited times, as few times as possible,
expanding as needed.
\< matches the character < literally
\/ matches the character / literally
p matches the character p literally (case sensitive)
\> matches the character > literally
so the problems in your regex are:
- in < p> there should be no ">".
- in < /p> you should escape the "<, / , >" characters by adding "\" before them.
hope this helped.