Skip to content

Commit 3165c70

Browse files
committed
minor #6241 [ExpressionLanguage] Add caution about backslash handling (zerustech, WouterJ)
This PR was merged into the 2.7 branch. Discussion ---------- [ExpressionLanguage] Add caution about backslash handling Finishes #5576 Original description: > 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 Commits ------- 31d74e5 Add a caution about backslash escaping 07f8e40 [components][expression_language] Add doc for backslashes
2 parents 309d29f + 31d74e5 commit 3165c70

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

components/expression_language/syntax.rst

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ The component supports:
2020
* **booleans** - ``true`` and ``false``
2121
* **null** - ``null``
2222

23+
.. caution::
24+
25+
A backslash (``\``) must be escaped by 4 backslashes (``\\\\``) in a string
26+
and 8 backslashes (``\\\\\\\\``) in a regex::
27+
28+
echo $language->evaluate('"\\\\"'); // prints \
29+
$language->evaluate('"a\\\\b" matches "/^a\\\\\\\\b$/"'); // returns true
30+
31+
Control characters (e.g. ``\n``) in expressions are replaced with
32+
whitespace. To avoid this, escape the sequence with a single backslash
33+
(e.g. ``\\n``).
34+
2335
.. _component-expression-objects:
2436

2537
Working with Objects

0 commit comments

Comments
 (0)