Skip to content

Instantly share code, notes, and snippets.

@ilham76c
Created July 15, 2023 17:19
Show Gist options
  • Select an option

  • Save ilham76c/6f77a44210aba5dcce9912383bb0be0c to your computer and use it in GitHub Desktop.

Select an option

Save ilham76c/6f77a44210aba5dcce9912383bb0be0c to your computer and use it in GitHub Desktop.

Revisions

  1. ilham76c renamed this gist Jul 15, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. ilham76c created this gist Jul 15, 2023.
    46 changes: 46 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    ## Definitions

    ## Look ahead positive `(?=)`

    Find expression A where expression B follows:

    ```plaintext
    A(?=B)
    ```

    ## Look ahead negative `(?!)`

    Find expression A where expression B does not follow:

    ```plaintext
    A(?!B)
    ```

    ## Look behind positive `(?<=)`

    Find expression A where expression B precedes:

    ```plaintext
    (?<=B)A
    ```

    ## Look behind negative `(?<!)`

    Find expression A where expression B does not precede:

    ```plaintext
    (?<!B)A
    ```

    ## Atomic groups `(?>)`

    An atomic group exits a group and throws away alternative patterns after the _first_ matched pattern inside the group (backtracking is disabled).

    * `(?>foo|foot)s` applied to `foots` will match its 1st alternative `foo`, then fail as `s` does not immediately follow, and stop as backtracking is disabled

    A non-atomic group will allow backtracking; if subsequent matching ahead fails, it will backtrack and use alternative patterns until a match for the entire expression is found or all possibilities are exhausted.

    `(foo|foot)s` applied to `foots` will:

    1. match its 1st alternative `foo`, then fail as `s` does not immediately follow in `foots`, and backtrack to its 2nd alternative;
    2. match its 2nd alternative `foot`, then succeed as `s` immediately follows in `foots`, and stop.