Notes on REGEX with its application in python and git-ci.yml etc.
-
[a-m]
txt = "The rain in Spain"
import re
re.findall("[a-m]", txt)- ['h', 'e', 'a', 'i', 'i', 'a', 'i']
-
'*' - 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
-
^ Starts with
txt = "hello planet"
x = re.findall("^hello", txt)
Yes, the string starts with 'hello' -
$ Ends with
txt = "hello planet"
x = re.findall("planet$", txt)
Yes, ends with starts with 'planet' -
'*' 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
-
"\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