-1

I am using this library with this line of text

#asdfasdf #日本語 スペース @漢字 #日本語 あ http://url file:///url「おくむら」最高ー!…

And it gives me right values

#asdfasdf #日本語

But in code there is % in regex

'%(\A#(\w|(\p{L}\p{M}?)|-)+\b)|((?<=\s)#(\w|(\p{L}\p{M}?)|-)+\b)|((?<=\[)#.+?(?=\]))%u'

What does this percent sign do?

In iOS it works without percent sign like this.

"(\\A#(\\w|(\\p{L}\\p{M}?)|-)+\\b)|((?<=\\s)#(\\w|(\\p{L}\\p{M}?)|-)+\\b)|((?<=\\[)#.+?(?=\\]))"

In php it gives me error: preg_match_all(): Unknown modifier '|'

What does this percent sign do?

matar
  • 127
  • 1
  • 12
  • 1
    Nothing, it is the delimiter to separate the regex from the additional options. They are required in the `preg_*` library, see http://php.net/manual/en/regexp.reference.delimiters.php – jeroen Feb 25 '16 at 09:55
  • *PHP: [pattern syntax](http://php.net/manual/en/reference.pcre.pattern.syntax.php)* links to the relevant documentation, the *Delimiters* is the second bullet point. – Wiktor Stribiżew Feb 25 '16 at 10:00

1 Answers1

0

Nothing, it is the delimiter to separate the regex from the additional options. They are required in the preg_* library, see http://php.net/manual/en/regexp.reference.delimiters.php.

Note that if you don't use the % in your regex, the ( ... ) will be used as the delimiter, leading to an error when you need to use them in your regex itself and you don't escape them.

Which is happening here in your case:

(\\A#(\\w|(\\p{L}\\p{M}?)|
                        ^ Here the regex engine thinks you are closing the expression
jeroen
  • 88,615
  • 21
  • 107
  • 128