$text = "the letter a is a vowel"
$reg-ex = "/thesletters[aeiou]sissasvowel/i";
Search for "the letter " followed by one of the letters a,e,i,o,u and none other
Followed by " is a vowel"
$matcheswill hold “the letter “a” is a
vowel” , there will be no other parts in
$matchesas there are no bracket sections.
sis a special character called a meta-
character, and it means anything classed as white space.
*symbol is also
a meta character and means match “0 or more occurrences” eg:
A‘, the ^ and
$meta characters mean start and end of the text, so:
a phrase as long as it starts with an ‘
at the beginning, which is different to the previous,
because that will match on the first ‘
encounters in the text, then match on the rest of the line,
and that brings us to my next point.
They will try and match the largest amount possible at any
given time in any given match string, which is why you
really only want to use
*if it’s really necessary, if you
can, always try to narrow your search as much as possible
"Alan went to meet marsha"
for a 4 character word beginning with ‘A’ right at the
beginning of the line, followed by a space and at least 1 or
description, and only 4 characters. It’s also possible to
specify ranges. Take a look at this example:
followed by between 1 and 4 characters, but no less than 1
and no more than 4. And this snippet:
beginning followed by at least 4 characters, possibly more.
this does not just have to be a ‘
*‘ or ‘
+‘ , you can use a
character class like this:
beginning with ‘
A‘ and at least 4 of any of the
characters in the square brackets in any order, but only the
characters in the square brackets.
tip of the iceberg with regular expressions, it’s a huge
subject for which many books have been written. I urge you
to read more about them and you can always look to the PHP
manual, the expressions section is at https://phpbuilder.com/manual/en/language.expressions
in our series, in which we wrap up and look at some
practical examples of what we’ve learned so far.
what you’d like to cover. If there is a particular thing
you’ve been trying to do, or a technique your not sure how
to make work, then please leave a comment using the form at
the bottom of this page.
I’ll be checking these comments, and I’ll use them as a
basis for what I put in the last article, please note
however, I’m not going to complete your project for you or
your homework assignment, so please don’t put things in like
“please show me how to make a project that does xxxx” all
I’m looking for are real world ideas based on common
scenarios that you guys are currently learning.