ereg("%[a-z0-9]","%foo%") that evaluates to true
ereg("%[a-z0-9]%","%foo%") that does not. I've tried escaping the 2nd % with \ etc to no avail. I have also tried encapsulating each % in their own [] also with no luck. Can a regex person help? Thanks in advance.
look at the expression. in the first expression you're looking for a percent sign followed by an optional alphanumeric lower case character. in the second expression you're looking for a percent sign followed by a single optional alphanumeric lower case character followed by another percent sign. because the submitted example "%foo%" has more than one character between the percent signs the ereg evaluates to false. change your ereg to: ereg("%[a-z0-9]*%","%foo%");
this will look for a percent sign followed by 0 or more alphanumeric characters and then another percent sign.
Thanks Brandon -- it also worked for me when I pulled the %'s into the [] like this:
ereg("[%a-z0-9%]","%foo%");
which is better technically?
depends on what you're looking for. pulling the percent signs into the brackets will have ereg returning true if it finds a single alphanumeric/percent character in the entire text.
for example, the text "~!@#$%&*()" would evaluate to true because it contains a percent sign.
ahh. Duh! /me pulls out old Perl book, blows dust off cover...
A haikau (sp) in your honor:
Thank you sir, Your regex is betta, I feel dumb