Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let’s talk patterns

Let’s talk patterns

Not a few times, we had to look for some pieces of code or text fragments that had a pattern. These fragments are also called patterns so Let's talk patterns!

98ede30a4a96e7c5547dc964b391e2ed?s=128

Sibiu Web Meetup

February 08, 2019
Tweet

More Decks by Sibiu Web Meetup

Other Decks in Programming

Transcript

  1. LET’S TALK PATTERNS. /andreifilip96 /elfelipe1996 /andreifilip123

  2. SOME PEOPLE, WHEN CONFRONTED WITH A PROBLEM, THINK "I KNOW,

    I’LL USE REGULAR EXPRESSIONS". NOW THEY HAVE TWO PROBLEMS. Jamie Zawinski
  3. Why ? What ? How ? REGEX

  4. None
  5. CHARACTERS ▸ \w - word characters ▸ \d - digits

    ▸ \s - whitespaces(\n, \r, \t, \f) ▸ \W - non-word characters ▸ \D - non-digits ▸ \S - non-whitespaces(\n, \r, \t, \f) . - any character except \n
  6. QUANTIFIERS ▸ * - matches 0 or many ▸ +

    - matches 1 or many ▸ ? - matches 0 or 1 ▸ ?? - lazy matches 0 or 1 ▸ {x} - matches exactly x ▸ {x,} - matches x or more ▸ {x, y} - matches x to y times POSITION MATCHING ▸ ^ - start of line in multi-line mode ▸ $ - end of line in multi-line mode ▸ \A - start of string ▸ \Z - end of string ▸ \b - matches word boundary ▸ \B - matches non-word boundary
  7. GROUPS ▸ Syntax: (…) ▸ Also called capturing groups ▸

    Syntax: (?…) ▸ Also called non-capturing groups PASSIVE GROUPS ▸ Syntax: [aef135] ▸ Also called character classes ▸ ^ for negated character class ▸ Syntax: [a-z0-9] ▸ Useful for large sets SETS RANGES
  8. ASSERTIONS ▸ ?= - positive lookahead ▸ ?! - negative

    lookahead ▸ ?<= - positive lookbehind ▸ ?<! - negative lookbehind
  9. THE BEST WAY TO LEARN SOMETHING IS BY DOING IT

    !
  10. BUT FIRST, QUESTIONS ?