Differences Preg_match?

I want to ask, what is the meaning or difference between these two lines?

  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 on this line mean? (Arrow)

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

Thank!

+3
source share
3 answers

I will answer the second part of your question:

{3,30}in regular expression means quantifierfor a minof 3and max 30 repetitions.

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

a. : [a-zA-Z]{3,30} 3 30 .

+3

(, , ), 2- .

0

Unicode Unicode.

\x {FFFF}, FFFF - 1 4
Perl . .

:
\ x {E0} U + 00E0.
\ x {A9} ©

Thus it tries to match every Unicode character from U+4e00 to U+9fa5 (from to ) whereas the last one is not a valid Unicode character.


The first expressions also try to match these characters ( 一-龥), but they are not expressed in Unicode syntax (regardless of whether this contradicts a problem that I don't know). In addition (as already mentioned) the first expression corresponds to a greater number of characters, namely א-תand À-ÿ.


The second question was already answered very well by unicornaddict.

0
source

Source: https://habr.com/ru/post/1742235/


All Articles