Skip to content

Commit 98d7783

Browse files
committed
[components][expression_language] Add doc for backslashes
Additional backslashes are required to escape a backslash(``\``) in a string or regex because a string will be stripped by the lexer. This should be documented here, otherwise, user may feel confused about the unexpected behavior. | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | ~2.4 | Fixed tickets | n/a
1 parent 3d88312 commit 98d7783

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

components/expression_language/syntax.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ Comparison Operators
181181
You must use parenthesis because the unary operator ``not`` has precedence
182182
over the binary operator ``matches``.
183183

184+
A backslash(\) must be escaped by 4 backslashes(``\\\\``) in a string and
185+
8 backslashes(``\\\\\\\\``) in a regex::
186+
187+
$language->evaluate('"\\\\"');
188+
// returns \
189+
190+
$language->evaluate('"a\\\\b" matches "/^a\\\\\\\\b$/"');
191+
// returns true
192+
193+
This is because the backslashes in a string will be stripped by the
194+
``stripcslashes()`` function and the stripped slashes in a regex will be
195+
stripped again by the regex engine.
196+
184197
Examples::
185198

186199
$ret1 = $language->evaluate(

0 commit comments

Comments
 (0)