Hi
I am trying to write a simple regular expression that will help me lookup
all the occurrences of & followed by a-z or A-Z with the following exception;
(case insensitive) should not be matched
so I will be able to find:
&aad
&De
but not:
&&
&NBSp;
any help would be appreciated
help with a simple regular expression
Moderator: General Moderators
- mattcooper
- Forum Contributor
- Posts: 210
- Joined: Thu Mar 17, 2005 5:51 am
- Location: London, UK
This'll help you along...
Run it and see what happens; hopefully you'll be able to extrapolate the rest of what you need from there!
Hope this helps.
Code: Select all
$exclude=" ";
$text="&NBSP";
if(eregi($exclude, $text)){ // compare the variables and check for a case-insensetive match
echo "Match";
}
else{
echo "No match";
}Hope this helps.
Moved to Regex forum.
Try this:
That's a pattern to use with preg_match(), not ereg()
Also, take a look at ~ d11wtq's Regex Advanced Tutorial II. You might find some useful stuff in there.
Try this:
Code: Select all
'/&(?!nbsp)[a-zA-Z]+/i'Also, take a look at ~ d11wtq's Regex Advanced Tutorial II. You might find some useful stuff in there.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- mattcooper
- Forum Contributor
- Posts: 210
- Joined: Thu Mar 17, 2005 5:51 am
- Location: London, UK
Am I to take it that, in this instance, I was grossly incorrect?!pickle wrote:a pattern to use with preg_match(), not ereg()
Not at all. preg_match() uses the PCRE and is often faster than eregi(). That also means the patterns will look different.
I was just saying that because I saw you're example used eregi() and I didn't want him trying to use my pattern in eregi() (as it wouldn't ever work).
I was just saying that because I saw you're example used eregi() and I didn't want him trying to use my pattern in eregi() (as it wouldn't ever work).
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- mattcooper
- Forum Contributor
- Posts: 210
- Joined: Thu Mar 17, 2005 5:51 am
- Location: London, UK
Excellent news! I often find myself wanting to further my own understanding of PHP by taking on other developers' problems and have come a-cropper a few times and been, in a manner of speaking, "pulled-up" on it.
It's good to know that I'm not leading someone astray in this instance! Thanks fella...
It's good to know that I'm not leading someone astray in this instance! Thanks fella...