Skip to content

saurabh021184/REGEX

Repository files navigation

REGEX

Notes on REGEX with its application in python and git-ci.yml etc.

  1. [a-m]
    txt = "The rain in Spain"
    import re
    re.findall("[a-m]", txt)

    • ['h', 'e', 'a', 'i', 'i', 'a', 'i']
  2. '*' - Zero or more occurrences
    txt = "hello planet"
    import re
    x = re.findall("he.*o", txt)

    NOTE: here we used a DOT alongwith a STAR -> '.*' -> basically DOT represents to search the character

  3. ^ Starts with
    txt = "hello planet"
    x = re.findall("^hello", txt)
    Yes, the string starts with 'hello'

  4. $ Ends with
    txt = "hello planet"
    x = re.findall("planet$", txt)
    Yes, ends with starts with 'planet'

  5. '*' Zero or more occurrences -> "he.*o"
    '+' One or more occurrences -> "he.+o"
    '?' ZERO or ONE occurrences -> "he.?o"
    {} Exactly the specified number of occurrences -> "he.{2}o"

    NOTE: you have used a DOT '.' in all the above examples because DOT REPRESENTS any characters

  6. "\d" Returns a match where the string contains digits (numbers from 0-9)
    txt = "The rain in Spain"
    import re
    x = re.findall("\d", txt)

    NO MATCH

References:

About

Notes on REGEX with its application in python and git-ci.yml etc.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published