Skip to content

Commit f1bd688

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 f1bd688

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

components/expression_language/syntax.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ 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+
Control characters must be defined as the escaped form of their escape sequences.
194+
Otherwise, they will be replaced by spaces and ignored::
195+
196+
$language->evaluate('"a\nb"');
197+
// returns a b
198+
199+
$language->evaluate('"a\\nb"');
200+
// returns a\nb
201+
202+
This is because the backslashes in a string will be stripped by the
203+
``stripcslashes()`` function and the stripped slashes in a regex will be
204+
stripped again by the regex engine.
205+
184206
Examples::
185207

186208
$ret1 = $language->evaluate(

0 commit comments

Comments
 (0)