"Long live PHP Builder in 2009"
$found = preg_match("/^.*(\d\d\d\d)$/", "Long live PHP Builder in 2009",$matches);
$foundwill be true if the text provided had 4 digits at the end of the string, the
/at either end of the pattern are how the regular expression engine knows the start and finish of the search (more on that in just a moment), if a match is found then the array matches will contain the following:
$matches = "Long live PHP Builder in 2009"
$matches = "2009"
^ = at the start of the line
. = Read any character
* = for as many as you can, until
\d\d\d\d = you encounter 4 digits in a row
$ = at the end of the string
() =keeps the part of the pattern you found in any rule between these separate, in this case the 4 digits.
$text = "Peter Shaw"
$reg-ex = "/(Peter)\s(Sh(aw|ore))/"
\s = look for the first space you encounter with
Peter = on the left side of it and
Sh = on the right side, followed by either
(aw|ore) = 'aw' OR 'ore'
In all cases keep the 2 found words.
$matches = "Peter Shaw" (or "Peter Shore")
$matches = "Peter"
$matches = "Shaw" (or "Shore")
$matches = "aw" (or "ore")
()to group the 2 parts either side of the OR decision, so even if you don't intend to look for that part, it still uses up a slot in the results.