Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preg_match differences?

i want to ask, what is the meaning or difference between these two line?

  1. if( preg_match_all('/\#([א-תÀ-ÿ一-龥а-яa-z0-9\-_]{1,50})/iu', $message, $matches, PREG_PATTERN_ORDER) ) {

  2. if( preg_match_all('/\#([а-яa-z0-9\-_\x{4e00}-\x{9fa5}]{1,50})/iu', $message, $matches, PREG_PATTERN_ORDER) ) {

and what does the number 3 mean in this line? (Arrow pointing)

if( preg_match_all('/\@([a-zA-Z0-9\-_\x{4e00}-\x{9fa5}]{->3,30})/u', $message, $matches, PREG_PATTERN_ORDER) ) {

Thanks!

like image 528
sky Avatar asked Aug 28 '26 07:08

sky


1 Answers

I'll answer the 2nd part of your question:

The {3,30} in the regex means quantifier for a min of 3 and a max of 30 repetitions.

  • a* means zero or more a
  • a+ means one or more a
  • a? means zero or one a
  • a{1} means exactly one a same as just a
  • a{1,} means one or more a same as a+
  • a{1,3} means min of one and max of 3 a's

you can have any complex regex in place of a. Example: [a-zA-Z]{3,30} would mean at least 3 and at max 30 of any of the alphabets.

like image 85
codaddict Avatar answered Aug 29 '26 21:08

codaddict



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!