Skip to content

Commit

Permalink
[DOCS] Adds note about escaping backslashes in regex (elastic#89276) (e…
Browse files Browse the repository at this point in the history
…lastic#89405)

* [DOCS] Adds note about escaping backslashes in regex

* Fix typo

* Simplify example
  • Loading branch information
abdonpijpelink committed Aug 17, 2022
1 parent ac4e1ac commit 71ae739
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion docs/reference/query-dsl/regexp-syntax.asciidoc
Expand Up @@ -37,7 +37,38 @@ backslash or surround it with double quotes. For example:
\\ # renders as a literal '\'
"john@smith.com" # renders as 'john@smith.com'
....


[NOTE]
====
The backslash is an escape character in both JSON strings and regular
expressions. You need to escape both backslashes in a query, unless you use a
language client, which takes care of this. For example, the string `a\b` needs
to be indexed as `"a\\b"`:
[source,console]
--------------------------------------------------
PUT my-index-000001/_doc/1
{
"my_field": "a\\b"
}
--------------------------------------------------
This document matches the following `regexp` query:
[source,console]
--------------------------------------------------
GET my-index-000001/_search
{
"query": {
"regexp": {
"my_field.keyword": "a\\\\.*"
}
}
}
--------------------------------------------------
//TEST[continued]
====

[discrete]
[[regexp-standard-operators]]
Expand Down

0 comments on commit 71ae739

Please sign in to comment.