Reputation: 21
Could you please explain the statement below? I think it's called regex, but I'm really not sure.
~<p>(.*?)</p>~si
What does si
and (.*?)
stand for?
Upvotes: 1
Views: 614
Reputation: 31564
Actually, it's called regex, short for Regular Expression, and has a syntax that doesn't look familiar at first, but becomes second-nature quickly enough.
si
are flags: s
stands for "dotall", which makes the .
(which I'll explain in a bit) match every single character, including newlines. The i
stands for "case-insensitive", which is self-explanatory.
The (.*?)
part says this: "match every 0 or more repetitions (*
) of any character (.
), and make it greedy lazy (?
) i.e. match as few characters as possible".
The "matching" happens when you check a string against the regex. For example, you say that <p>something</p>
matches the given regex.
You'll find @Mchl's link a great source of information on regex.
Hope this helps.
Upvotes: 4
Reputation: 62395
Find everything between <p>
and </p>
case insensitive (i
) (so <P>
will work also) and possibly spanning multiple lines (s
)
Upvotes: 4
Reputation: 13371
It's called regex - short for regular expressions, which is a standard for string parsing, manipulation, and validation. Look at the reference section on the site I linked to and you'll be able to work out what that regex does.
Upvotes: 1
Reputation: 9567
It's a lazy regular expression, basically it will try as LITTLE (lazy) as possible with that mask while by default it will try to match as much as it can (greedy).
Check out this resource for a better, more complete explanation:
http://www.regular-expressions.info/repeat.html#greedy
Upvotes: 0