--- Gordon Stewart <[EMAIL PROTECTED]> wrote:
> if (preg_match("/^\s*NEW ARCHIVE
> SEARCH\s+(\w*.*\w*?)\s+(\w.*?\w)\s*$/i", $val,$matches)){
>
>
> Hi,
>
> I'm altering one of my pregs - & wondering if the above will work in
> all cases (it seems to work..)
>
> Basically, the person will put the text
>
> NEW ARCHIVE SEARCH
>
> and then two bits of changeable data.. -
>
> the 2nd word/phrase MUST have a letter (a-z), & end in an (a-z).. -
> But can contain a dash or no dash..
>
>
> the 1st input, I want to enter a partial email address - or a full
> email address..
>
> I entered a search term of "4" - to find email addresses with the
> number 4 in it... - & my previous preg didn't work... so Ive changed
> it to the above - Which seems to work...
>
> I think its going ok - But im just curious - Does anyone see a problem
> with the above preg ?
>
> --
> G
This part:
\w*.*\w*?
expands out to:
[A-Za-z0-9]* -- Any letter or number, the * means 0 or more of this set
.* -- Any character other than the newline, 0 or more of this
[A-Za-z0-9]*? -- shortest match (?) of 0 or more of any letter or number
I don't think this matches your description:
> the 2nd word/phrase MUST have a letter (a-z), & end in an (a-z).. -
> But can contain a dash or no dash..
The rest of the expression:
\s+(\w.*?\w)\s*
\s+ -- sequence of one or more whitespace characters
[A-Za-z0-9] -- any letter or numeric digit
.*? -- shortest match of 0 or more of any character (other than newline)
[A-Za-z0-9] -- any letter or numeric digit
This pattern won't really grab an email address in most cases. At least you
are not getting the specific pattern of an email.
If you really need to have a letter at the beginning and end of the word, you
should use the [A-Za-z] pattern instead of \w
You ask if this will cover all cases, I'd say that there are a number which
would not be covered. I'm sure a proper regex can be devised to meet your
needs.
James Keeline