Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
[[painless-regexes]]
|
|
|
|
=== Regexes
|
|
|
|
|
|
|
|
Regular expression constants are directly supported. To ensure fast performance,
|
|
|
|
this is the only mechanism for creating patterns. Regular expressions
|
|
|
|
are always constants and compiled efficiently a single time.
|
|
|
|
|
|
|
|
[source,painless]
|
|
|
|
---------------------------------------------------------
|
|
|
|
Pattern p = /[aeiou]/
|
|
|
|
---------------------------------------------------------
|
|
|
|
|
2020-07-20 15:05:33 -04:00
|
|
|
WARNING: A poorly written regular expression can significantly slow performance.
|
|
|
|
If possible, avoid using regular expressions, particularly in frequently run
|
|
|
|
scripts.
|
|
|
|
|
Painless: Restructure/Clean Up of Spec Documentation (#31013)
Full restructure of the spec into new sections for operators, statements, scripts, functions, lambdas, and regexes. Split of operators into 6 sections, a table, reference, array, numeric, boolean, and general. Clean up of all operators sections. Sporadic clean up else where.
2018-06-07 20:11:56 -04:00
|
|
|
[[pattern-flags]]
|
|
|
|
==== Pattern flags
|
|
|
|
|
|
|
|
You can define flags on patterns in Painless by adding characters after the
|
|
|
|
trailing `/` like `/foo/i` or `/foo \w #comment/iUx`. Painless exposes all of
|
|
|
|
the flags from Java's
|
|
|
|
https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html[
|
|
|
|
Pattern class] using these characters:
|
|
|
|
|
|
|
|
[cols="<,<,<",options="header",]
|
|
|
|
|=======================================================================
|
|
|
|
| Character | Java Constant | Example
|
|
|
|
|`c` | CANON_EQ | `'å' ==~ /å/c` (open in hex editor to see)
|
|
|
|
|`i` | CASE_INSENSITIVE | `'A' ==~ /a/i`
|
|
|
|
|`l` | LITERAL | `'[a]' ==~ /[a]/l`
|
|
|
|
|`m` | MULTILINE | `'a\nb\nc' =~ /^b$/m`
|
|
|
|
|`s` | DOTALL (aka single line) | `'a\nb\nc' =~ /.b./s`
|
|
|
|
|`U` | UNICODE_CHARACTER_CLASS | `'Ɛ' ==~ /\\w/U`
|
|
|
|
|`u` | UNICODE_CASE | `'Ɛ' ==~ /ɛ/iu`
|
|
|
|
|`x` | COMMENTS (aka extended) | `'a' ==~ /a #comment/x`
|
|
|
|
|=======================================================================
|