Today I have been on my daily routine of checking my social media. Suddenly I fell in love with a post on Linkedin which explains popular regular expressions in a short time. Regular expressions are easily understandable but remembering those exact ones is really a big task.
Regex is supported by almost many languages out there in the market right from bash to python etc..
Let's see
cat matches cat
ca+t matches caaaaaaaaaaaaat but not ct
ca*t matches caaaaaaaaaaaaat and also ct
ca{2,4}t matches caat, caaat and caaaat
c(at)+ matches catatatatatat
c(at|orn) matches cat and corn
c[ea]t matches cat and cet
c[ea]+t matches caaaat, ceeet and caaeaeaaet
c[A-C0-9]t matches cAt, cBt, cCt, c8t etc.
c.t matches cat, c&t, c2t (any char between c and t)
c.+t matches c3%x4t (any number of any chars)
c.*t matches c3%x4t and as well as ct
^ denotes start of a string, $ denotes the end
^a+cat will match aaacat in aaacat but not in bbbaaacat
cat$ will match cat in aaacat but not in aaacats
^cat$ will match only and only this string i.e. cat
\d is for digits, \w for alphanumeric chars, \s is white space & line breaks
\D is for non-digits, \W for non-alphamueric chars and \s is for non-white space chars
\t for tabs, \r for carriage return and \n for newline
Using .*w vs .*?w on somethingnew@1234w
.*w returns somethingnew@1234w (longest match)
.*?w returns somethingnew (shortest match)
I must thank the author (Somdev Sangwan ).
Regex , Regular Expressions in 2 mins

Add Comments
Saturday, September 14, 2019
Nice find
ReplyDelete