php - preg_match() with backslashes doesn't work as expected / throws error -
i need preg_match()
pattern in php , no matter errors.
i've looked on net , can't find tells me i'm doing wrong.
here's preg_match
pattern:
preg_match('/\myapp\library\task\/', '\myapp\library\task\db\generate');
it returns array, do wrong? how can regex work properly?
i know sound crazy, need use 4 backslashes 1 backslash regex. code this:
preg_match('/\\\\myapp\\\\library\\\\task\\\\/', '\myapp\library\task\db\generate');
why need use 4? because in php use backslash escape following character, escape 1 literal backslash (\\
).
but since are in regular expression need escape backslash if want backslash in regex, means have use \\
2 backslashes php end in 1 escape other 2 backslashes end in 1 character, end single backslash in regex.
Comments
Post a Comment