Monday, September 28, 2020

Regular Expressions - Basics

  

  • ^  = starting of the line

  • $ = Ending of the line

  • .   =  (dot) match any single character

    • 03.10.16

      • matches 03-10-16, 03/10/16, 30.10.16

  • *  =  (asterisk) match zero/more occurrence of previous character 

  • |  = combination of two

  • [ ] = Character class, either of two

    • Gr[eay] searches both Grey and Gray

    • <H[12345]>

      • Finds HTML headers

      • <H1> <H2> <H3> <H4> <H5>

    • Metacharacter - both the below are similar.

      • [0-9a-fA-F]

      • [0123456789abcdefABCDEF]

  • Negation - [^...]

    • [^1-6] → matches the character that is not 1 to 6

  • Alternation

    • uses the parentheses ‘(‘ ‘)’

    • to find first, 1st

      • (fir|1)st

    • ^(from|subject|date):

      • matches the start of line and then from or subject or date

  • Word Boundaries

    • \<  → start of the word

    • \>  → End of word

    • /<cat/> → finds the word cat

    • /<cat → finds the word starts with cat

    • cat/> → word ends with cat

  • Optional items

    • ?

    • attaches only to immediately to preceding item.

    • for matching color or colour 

      • colou?r → u is optional in searching. 

  • Repetition

    • +  → one or more immediately preceding item 

    • * → any number, including zero.

  • Escape Character

    • \

    • match the dot →  \.

    • match the parenthesis → \(    \)

  • A span of characters

    • \{   \}

    • \{n\} -- exactly n occurrences

    • \{n,\}  - atleast n occurrences.

    • \{n,m\}  -- any occurrence between n and m will be matches

    • For ex

      • 10\{2,4\}1

        • matches 1001, 10001, 100001

No comments:

Post a Comment

Minicom

 Installation sudo apt install minicom Configuration Giving permission to user for accessing the serial port chmod 666 /dev/ttyUSB0 after th...