Expert
I swear I surf a lot of regular expression stuff to study but I find regular expression topic is too difficult to me understand. Any good suggestion for me?
Anyone can explain to me why this <p[^>]*> can simply remove the start <p> or <p attr="">?
And what could I do, if I want make it from
<div style="float: left; width: 350px; border: 1px solid #000000;" class="star1">abcdk</div>
to this
<div class="star1">abcdk</div>
Thanks in advance.
Suggestion: Play around with a regex tester to get the hang of what matches what.
Jason’s explanation was good, but maybe not in-depth enough for you if you’re just starting out with regexes. Let’s take
<p[^>]*>a piece at a time:<has no special meaning to regex engines, so it means it just matches a single<[abc]would match any single character that is ‘a’, ‘b’, or ‘c’.[abc]would match any single character mentioned,[^abc]would match any single character not mentioned.>has no special meaning: just match a single>>still no special meaning, like earlierSo we can break
<p[^>]*>into three pieces, and we can say that it matches any series of characters:<p: that starts with a literal<p,[^>]*: which is followed by 0 or more characters that are not a>,>: and which ends with a literal>.Oh, and http://www.regular-expressions.info is one of the best regex guides I’ve ever found online.