Skip to content

Matching syntax

Amy Brennan-Luna edited this page Dec 1, 2020 · 5 revisions

Matching syntax reference

Note: capturing groups will ensure parentheses and braces match (unless otherwise specified)

Basic

:[group]

  • A group matching one or more characters, including whitespace and line terminators

:[?group]

  • An optional group matching zero or more characters
  • Any of the below syntax can be made optional by adding a ? in front of the group

Groups which match specific characters

:[group.]

  • Note: Has period at end
  • One or more alphanumeric characters or one of the following _ . -.
  • For example, could be used to match fully qualified or short names.

:[group:w]

  • One or more alphanumeric characters
  • Similar to \w+ in regex

:[group:d]

  • One or more digits
  • Similar to \d+ in regex

:[ group]

  • Note: Has space at beginning
  • One or more horizonal whitespace (ignoring line terminators)
  • Similar to \h+ in regex

Regex

@--regex--!

  • Include the specified regex as part of the pattern
  • This is useful if you want to match something specific as part of the structured matching
  • RegExPlus is used to provide regex matching
    • Extends Java's regular expression syntax
    • Supports all of Java's regex syntax plus more, such as numeric ranges, Perl's branch reset group, and more

Escaping

Note: in most cases, escaping is not necessary. However, to handle edge cases and also BEXPattern.literal and BEXMatcher.quoteReplacement, the following syntax can be used to escape.

:[:]

  • Escape colon in pattern
  • Usually not needed in typical cases, unless the : is followed by [
  • For example, no escaping is needed for the pattern `:[condition] ? :[true] : :[false]

:[@]

  • Escape at symbol in pattern
  • Usually not needed in typical cases, unless the @ is followed by --
  • For example, no escaping is needed for the pattern :[email]@:[provider].:[domain]
Clone this wiki locally