Skip to content

Commit 8e9ffd2

Browse files
[DOCS] Adds note about escaping backslashes in regex (#89276) (#89406)
* [DOCS] Adds note about escaping backslashes in regex * Fix typo * Simplify example
1 parent 74f25d0 commit 8e9ffd2

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

docs/reference/query-dsl/regexp-syntax.asciidoc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,38 @@ backslash or surround it with double quotes. For example:
3737
\\ # renders as a literal '\'
3838
3939
....
40-
40+
41+
[NOTE]
42+
====
43+
44+
The backslash is an escape character in both JSON strings and regular
45+
expressions. You need to escape both backslashes in a query, unless you use a
46+
language client, which takes care of this. For example, the string `a\b` needs
47+
to be indexed as `"a\\b"`:
48+
49+
[source,console]
50+
--------------------------------------------------
51+
PUT my-index-000001/_doc/1
52+
{
53+
"my_field": "a\\b"
54+
}
55+
--------------------------------------------------
56+
57+
This document matches the following `regexp` query:
58+
59+
[source,console]
60+
--------------------------------------------------
61+
GET my-index-000001/_search
62+
{
63+
"query": {
64+
"regexp": {
65+
"my_field.keyword": "a\\\\.*"
66+
}
67+
}
68+
}
69+
--------------------------------------------------
70+
//TEST[continued]
71+
====
4172

4273
[discrete]
4374
[[regexp-standard-operators]]

0 commit comments

Comments
 (0)