preg_match help

I came across these two code snippets that I’m having hard time understanding it… Not finding enough information about it online too…


preg_match("/.*h.*e.*l.*l.*o.*/",$line)

I’m having problem understanding with this part >> “/.*h.*e.*l.*l.o./”

why * been used and is . simply means concatenation?

another case


preg_match('/(1111111|0000000)+/', $ConsecutiveZero)

‘/(1111111|0000000)+/’

what does | means here? is it OR I thought php or was ||
and what does that + sign do at the end?

Thanks in advance…

These are regular expressions. Based on your questions, it sounds like you need more than just a few sentences of summary, so I’ll refer you instead to PHP’s documentation on this subject.

http://www.php.net/manual/en/book.pcre.php

and

http://www.php.net/manual/en/reference.pcre.pattern.syntax.php

Thanks a lot… I’m referring to those.

This has always been my favorite site for regex. http://www.regular-expressions.info/

Jeff is entirely correct in that if you’re starting to dig into regex you should spend some time to learn fully what they mean. However, to answer your immediate inquiries…

  • is used here as an indicator to say “0 or more”.
    the . means “any character”.
    so, this regular expression is read to be: Any number of characters, followed by an h, followed by any number of characters, followed by an e (etc, etc)

another case


preg_match('/(1111111|0000000)+/', $ConsecutiveZero)

‘/(1111111|0000000)+/’

what does | means here? is it OR I thought php or was ||
and what does that + sign do at the end?

|| is OR in php. But regex syntax is not PHP. | means OR in PCRE.
the +, again, is a numeric quantifier, meaning “1 or more”.
() are used to designate subpatterns.
so this regular expression reads:
“Either ‘111111’ or ‘000000’, followed by any number of instances of either ‘111111’ or ‘000000’.”