Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07f8e40

Browse filesBrowse files
zerustechwouterj
authored andcommitted
[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 309d29f commit 07f8e40
Copy full SHA for 07f8e40

File tree

Expand file treeCollapse file tree

1 file changed

+22
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-0
lines changed

‎components/expression_language/syntax.rst

Copy file name to clipboardExpand all lines: components/expression_language/syntax.rst
+22Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.