Re: Combining 2 preg matches.




Rik wrote:
frizzle wrote:
$regex ='/^(?:[a-z]|[a-z][_\-][a-z])+$/';

...will do just fine.

equally so:
$regex ='/^(?:[a-z]+(?:[_\-][a-z]+))+$/';

Lookahead & -behind are unneccessary in this case, and this keep it
simple.
Good point. It doesn't make sense to use assertions when you'll
capture
the matches anyway.
Somehow, i believe Rik's solution, gave me problems ...

'/^(?:[a-z0-9]|[a-z0-9][_\-][a-z0-9])+$/'; gave problems.
'/^(?:[a-z0-9]|(?<=[a-z0-9])[-_](?=[a-z0-9]))+$/' didn't.

An example string that gave problems is:
really_a_made_up_string


Ah, forgot that in [a-z0-9][_\-][a-z0-9] the character on the right is
already matched, so it won't work as a start for the second _ in _a_....

This one should still be working though:
$regex ='/^(?:[a-z0-9]+(?:[_\-][a-z0-9]+)*)$/';

Grtz,
--
Rik Wasmus

ok, dankjewel / thanks a lot.

Frizzle.

.



Relevant Pages

  • Re: Combining 2 preg matches.
    ... Rik wrote: ... Lookahead & -behind are unneccessary in this case, ... It doesn't make sense to use assertions when you'll capture ...
    (comp.lang.php)
  • Re: email all users in database help
    ... Also Rik, you provided 2 examples. ... mailing list question so I'm hoping this is not incredibly difficult to ... $mails = array; ... Rik Wasmus ...
    (alt.php)
  • Re: Parsing txt file
    ... Thankyou Rik, you solved the problem, and no I do not need to validate ... If you want to validate the IP adresses & portnumbers it's a whole other ... game. ... Rik Wasmus ...
    (comp.lang.php)
  • Re: Better understanding of PRIMARY, UNIQUE, INDEX...
    ... Creating more indexes on one field is useless. ... A primary index is ... Rik Wasmus ...
    (alt.php)
  • Re: Htaccess problem
    ... RewriteEngine On ... What's the questionmark doing there? ... Rik Wasmus ...
    (comp.lang.php)