R
R
roskoshinsky2015-01-22 17:16:32
Regular Expressions
roskoshinsky, 2015-01-22 17:16:32

1 = 2? Number of backslashes in regex?

Hello.
Such a problem:

$sCode = 'test"\\":"|"test';
$sPattern1 = "/(?<=\\\\)(\")/ismU";
preg_match_all($sPattern, $sCode, $aMatches1, PREG_OFFSET_CAPTURE);
$sPattern2 = "/(?<=\\\\{2})(\")/ismU";
preg_match_all($sPattern2, $sCode, $aMatches2, PREG_OFFSET_CAPTURE);
var_dump($aMatches1);
var_dump($aMatches2);

Despite the fact that 1 backslash is searched in the first pattern, it produces exactly the same result as the second pattern. The question is how to make the pattern see exactly two slashes (as in $sCode) ? ok, if we consider that there is a slash in line 1, then how to teach to see the pattern, that there is 1 slash, so that it does not work on 2?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question