Jump to content

preg_match


aim25

Recommended Posts

no, that will find 1 character that is anything BUT what you have...

from left to right...

/ => starts the regex

[ => starts a character group

^ => declares that the match should be anything except for what is in the character group

a-zA-Z0-9_\- => matches as you described

] => ends character group

/ => ends regex

 

also, you don't specify to search from beginning to send. so as long as there is ONE character that is NOT one of the ones you described, it will match. theoretically, you could use this, and a TRUE would mean it's not what you want, but let's modify the regex instead:

/^[\w\-]{5,15}$/

/ => starts the regex

^ => forces the match to start at the beginning of the string

[ => starts character group

\w => matches a-z, A-Z, 0-9, and underscore (much easier then writing all those out)

\- => matches a - (i think you can leave out the \ before it cus it's in a character group, but not 100% sure)

] => end character group

{5,15} => the previous character (or in our case character group) needs to repeat between 5 and 15 times

$ => forces the match to go to the end of the string

/ => ends character group

Link to comment
https://forums.phpfreaks.com/topic/114729-preg_match/#findComment-590024
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.