Skip to content

[components][expression_language] Add doc for backslashes #5576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions components/expression_language/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ Comparison Operators
You must use parenthesis because the unary operator ``not`` has precedence
over the binary operator ``matches``.

A backslash(``\``) must be escaped by 4 backslashes(``\\\\``) in a string and
8 backslashes(``\\\\\\\\``) in a regex::

$language->evaluate('"\\\\"');
// returns \

$language->evaluate('"a\\\\b" matches "/^a\\\\\\\\b$/"');
// returns true

Control characters must be defined as the escaped form of their escape sequences.
Otherwise, they will be replaced by spaces and ignored::

$language->evaluate('"a\nb"');
// returns a b

$language->evaluate('"a\\nb"');
// returns a\nb

This is because the backslashes in a string will be stripped by the
``stripcslashes()`` function and the stripped slashes in a regex will be
stripped again by the regex engine.

Examples::

$ret1 = $language->evaluate(
Expand Down