painless-regexes.asciidoc 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. [[painless-regexes]]
  2. === Regexes
  3. Regular expression constants are directly supported. To ensure fast performance,
  4. this is the only mechanism for creating patterns. Regular expressions
  5. are always constants and compiled efficiently a single time.
  6. [source,painless]
  7. ---------------------------------------------------------
  8. Pattern p = /[aeiou]/
  9. ---------------------------------------------------------
  10. [[pattern-flags]]
  11. ==== Pattern flags
  12. You can define flags on patterns in Painless by adding characters after the
  13. trailing `/` like `/foo/i` or `/foo \w #comment/iUx`. Painless exposes all of
  14. the flags from Java's
  15. https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html[
  16. Pattern class] using these characters:
  17. [cols="<,<,<",options="header",]
  18. |=======================================================================
  19. | Character | Java Constant | Example
  20. |`c` | CANON_EQ | `'å' ==~ /å/c` (open in hex editor to see)
  21. |`i` | CASE_INSENSITIVE | `'A' ==~ /a/i`
  22. |`l` | LITERAL | `'[a]' ==~ /[a]/l`
  23. |`m` | MULTILINE | `'a\nb\nc' =~ /^b$/m`
  24. |`s` | DOTALL (aka single line) | `'a\nb\nc' =~ /.b./s`
  25. |`U` | UNICODE_CHARACTER_CLASS | `'Ɛ' ==~ /\\w/U`
  26. |`u` | UNICODE_CASE | `'Ɛ' ==~ /ɛ/iu`
  27. |`x` | COMMENTS (aka extended) | `'a' ==~ /a #comment/x`
  28. |=======================================================================