Wildcard Patterns and Expressions - syntax reference

2022-05-18


Note: This is a "quick reference". The instructions are subjectively reduced to a minimum, to keep focus and clarity.


Wildcard Patterns

  • Special markers:

    • ? == any char
    • * == "" "any-chars"
    • a|b == a || b
  • A match action will skip over ./ or ../ at start of string, to avoid an unexpected match with .* in file-path.

  • A match action is case insensitive.


Wildcard Expressions

  • Special markers:

    • ? == any char

    • * == "" "any-chars"

    • a|b == a || b

    • [abc] == a || b || c

    • []abc[] == a || b || c || [ || ]

    • [!abc] == ! [abc] <==> [^abc] alias

    • [!]abc[] == ! []abc[]

    • [a!^] == a || ! || ^

    • [a-c] == a || b || c

  • Predefined classes:

    • \\s \\w \\d \\x [:s:] [:w:] [:d:] [:x:] == space word digit xdigit

    • \\S \\W \\D \\X [:S:] [:W:] [:D:] [:X:] == negated class

    • \\p \\P [:p:] [:P:] == Safe(r) Path chars, skip these chars:

      Ctrl SPC \" # $ % & \' ( ) * / : ; < > ? [ \\ ] { | } \`` DEL

    • (capture) == 1 occurrence <==> (1=capture) alias

    • (1=capture) == 1 occurrence

    • (?=capture) == 0..1 occurrences

    • (+=capture) == 1..n occurrences

    • (*=capture) == 0..n occurrences

    • (?-pattern) == non-capture variant, use - marker

    • (!-pattern) == negated match <==> (^=pattern) alias

    • (^-pattern) == negated match

  • Anchors:

    • < == start of word
    • > == end of word
    • ^ == start of haystack/line
    • $ == end of haystack/line
  • Escape other chars:

  • \\x == when x is not in predefined classes and is not an anchor a case sensitive match for exactly this char is expected.

  • A match action will skip over ./ or ../ at start of string, to avoid an unexpected match with .* in file-path.

  • A match action is case insensitive.


Note that:

  • Syntax allows expressions: *()* ?()? (1=?=) (1=*=) (1=1=)
  • To negate something use at the beginning: ! or ^

Previous Article Next Article

..