3 4 Anchors Description 5 \A restricts the match to start of string 6 \Z restricts the match to end of string 7 ^ restricts the match to start of line 8 $ restricts the match to end of line 9 \n newline character is used as line separator 10 \b restricts the match to start/end of words word characters: alphabets , digits, underscore 11 \B matches wherever \b doesn’t match 12 13 Feature Description 14 \ Escape_characters, to make non anchor 15 | multiple RE combined as conditional OR 16 (RE) group pattern(s), also a capturing group, a(b|c)d is same as abd|acd 17 (?:RE) non-capturing group 18 (?P<name>pat) named capture group 19 . Match any character except the newline character \n 20 [] Character class, matches one character among many 21 22 Greedy Quantifiers Description 23 * Match zero or more times 24 + Match one or more times 25 ? Match zero or one times 26 {m,n} Match m to n times (inclusive) 27 {m,} Match at least m times 28 {,n} Match up to n times (including 0 times) 29 {n} Match exactly n times 30 pat1.*pat2 any number of characters between pat1 and pat2 31 pat1.*pat2|pat2.*pat1 match both pat1 and pat2 in any order 32 33 Character class Description 34 [aeiou] Match any vowel 35 [^aeiou] ^ inverts selection, so this matches any consonant 36 [a-f] - defines a range, so this matches any of abcdef characters 37 \d Match a digit, same as [0-9] 38 \D Match non-digit, same as [^0-9] or [^\d] 39 \w Match word character, same as [a-zA-Z0-9_] 40 \W Match non-word character, same as [^a-zA-Z0-9_] or [^\w] 41 \s Match whitespace character, same as [\ \t\n\r\f\v] 42 \S Match non-whitespace character, same as [^\ \t\n\r\f\v] or [^\s] 43 44 lookarounds custom assertions, zero-width like anchors 45 (?!pat) negative lookahead assertion 46 (?<!pat) negative lookbehind assertion 47 (?=pat) positive lookahead assertion 48 (?<=pat) positive lookbehind assertion 49 (?!pat1)(?=pat2) multiple assertions can be specified in any order 50 as they mark a matching location without consuming characters 51 ((?!pat).)* Negate a grouping, similar to negated character class 52 53 Flags Description 54 re.IGNORECASE or re.I flag to ignore case 55 re.DOTALL or re.S allow . metacharacter to match newline character 56 flags=re.S|re.I multiple flags can be combined using | operator 57 re.MULTILINE or re.M allow ^ and $ anchors to match line wise 58 re.VERBOSE or re.X allows to use literal whitespaces for aligning purposes 59 and to add comments after the # character 60 escape spaces and # if needed as part of actual RE 61 re.ASCII or re.A match only ASCII characters for \b, \w, \d, \s 62 and their opposites, applicable only for Unicode patterns 63 re.LOCALE or re.L use locale settings for byte patterns and 8-bit locales 64 (?#comment) another way to add comments, not a flag 65 (?flags:pat) inline flags only for this pat, overrides flags argument 66 flags is i for re.I, s for re.S, etc, except L for re.L 67 (?-flags:pat) negate flags only for this pat 68 (?flags-flags:pat) apply and negate particular flags only for this pat 69 (?flags) apply flags for whole RE, can be used only at start of RE 70 anchors if any, should be specified after these flags 71 72 Matched portion Description 73 re.Match object details like matched portions, location, etc 74 m[0] or m.group(0) entire matched portion of re.Match object m 75 m[n] or m.group(n) matched portion of nth capture group 76 m.groups() tuple of all the capture groups’ matched portions 77 m.span() start and end+1 index of entire matched portion 78 pass a number to get span of that particular capture group 79 \N backreference, gives matched portion of Nth capture group 80 applies to both search and replacement sections 81 possible values: \1, \2 up to \99 provided no more digits 82 \g<N> backreference, gives matched portion of Nth capture group 83 possible values: \g<0>, \g<1>, etc (not limited to 99) 84 \g<0> refers to entire matched portion 85 (?P<name>pat) named capture group 86 refer as 'name' in re.Match object 87 refer as (?P=name) in search section 88 refer as \g<name> in replacement section 89 \0 and \100 onwards are considered as octal values, hence cannot be used as backreferences. 90 91 Function Description 92 re.search Check if given pattern is present anywhere in input string 93 Output is a re.Match object, usable in conditional expressions 94 r-strings preferred to define RE 95 Use byte pattern for byte input 96 Python also maintains a small cache of recent RE 97 re.compile Compile a pattern for reuse, outputs re.Pattern object 98 re.sub search and replace 99 re.sub(r'pat', f, s) function f with re.Match object as argument 100 re.escape automatically escape all metacharacters 101 re.split split a string based on RE 102 re.findall returns all the matches as a list 103 if 1 capture group is used, only its matches are returned 104 1+, each element will be tuple of capture groups 105 re.finditer iterator with re.Match object for each match 106 re.subn gives tuple of modified string and number of substitutions 107 108 ------------------------------------------------------------------------------ 109 110 import re 111 112 x = re.search(pattern, string, flags) 113 # checks for first match or None 114 x = re.compile(pattern, flags) 115 # creates pattern for search 116 x = re.findall(pattern, string, flags) 117 # returns a list of all matches without span 118 x = re.finditer(pattern, string, flags) 119 # returns all matches in iteration with span 120 x = re.fullmatch(pattern, string, flags) 121 # checks for the entire string/ input 122 x = re.match(pattern, string, flags) 123 # checks at the begining of the string 124 x = re.split(pattern, string, maxsplit, flags) 125 # split the string at matches, maxsplit gives no of splits 126 x = re.sub(pattern, replace, string, count, flags) 127 # substitute the replacement at match 128 x = re.subn(pattern, replace, string, count, flags) 129 # gives tuple with replacement at match with replacement count 130 re.purge() 131 # the function to clear the regular expression cache 132 re.escape() 133 # re.escape escapes all the characters in the pattern other than ASCII letters and numbers. 134 ------------------------------------------------------------------------------ 135 1.re.search(pattern, string, flags) 136 txt = "The rain in Spain" 137 x = re.search("ai", txt) 138 print(x) 139 # <re.Match object; span=(5, 7), match='ai'> 140 141 x = re.search("\s", txt) 142 print("The first white-space character is located in position:", x.start()) 143 # The first white-space character is located in position: 3 144 145 # The properties of match object 146 # 1. span() 147 # 2. string 148 # 3. group() 149 x = re.search(r"\bS\w+", txt) 150 print(x.span()) 151 # (12, 17) 152 153 x = re.search(r"\bS\w+", txt) 154 print(x.string) 155 # The rain in Spain 156 157 # match group is depend on the pattern having how many () are there. 158 txts = "Please sent the mail to [email protected]" 159 x = re.search(r"(\bSh\w+)@([\w.-]+)", txts) 160 print(x.group()) 161 # [email protected] 162 print(x.group(1)) 163 # Shetty 164 print(x.group(2)) 165 # gmail.com 166 print(x.groups()) 167 # ('Shetty', 'gmail.com') 168 169 2.re.compile(pattern, flags) 170 p = re.compile('[a-e]') 171 # findall() searches for the Regular Expression and return a list upon finding 172 print(p.findall("Aye, said Mr. Gibenson Stark")) 173 # ['e', 'a', 'd', 'b', 'e', 'a'] 174 175 3.re.findall(pattern, string, flags) 176 x = re.findall("ai", txt) 177 print(x) 178 # ['ai', 'ai'] 179 180 4.re.finditer(pattern, string, flags) 181 x = re.finditer("ai", txt) 182 for p in x: 183 print(p) 184 # <re.Match object; span=(5, 7), match='ai'> 185 # <re.Match object; span=(14, 16), match='ai'> 186 187 5.re.fullmatch(pattern, string, flags) 188 x = re.fullmatch("The(.|\n)*", txt) # output if whole string match with pattern otherwise None 189 print(x) 190 # <re.Match object; span=(0, 17), match='The rain in Spain'> 191 192 6.re.match(pattern, string, flags) 193 x = re.match("The", txt) # output if start of string match with pattern otherwise None 194 print(x) 195 # <re.Match object; span=(0, 3), match='The'> 196 197 7.re.split(pattern, string, maxsplit, flags) 198 x = re.split(' ', txt) 199 print(x) 200 # ['The', 'rain', 'in', 'Spain'] 201 # string split doesnot seperate the general numbers and donot support all patterns 202 203 x = re.split('\s', txt, 2) # splited by space 204 print(x) 205 # ['The', 'rain in Spain'] # maxsplit=1 206 # ['The', 'rain', 'in Spain'] # maxsplit=2 207 # ['The', 'rain', 'in', 'Spain'] # maxsplit=3 208 209 8.re.sub(pattern, replace, string, count, flags) 210 x = re.sub('\s', '.', txt) 211 print(x) 212 # The.rain.in.Spain 213 214 x = re.sub("\s", "9", txt, 2) 215 print(x) 216 # The9rain9in Spain 217 218 9.re.subn(pattern, replace, string, count, flags) 219 x = re.subn("\s", "9", txt, 3) 220 print(x) 221 # ('The9rain9in9Spain', 3) 222 223 10.re.escape() 224 re.escape('new**world') 225 # ‘new\\*\\*world’ 226 ------------------------------------------------------------------------------ 227 1.[] 228 # []:A set of characters "[a-m]" 229 x = re.findall("[a-m]", txt) 230 print(x) 231 # ['h', 'e', 'a', 'i', 'i', 'a', 'i'] 232 233 2.. 234 # . :Any character (except newline character) "he..o" 235 x = re.findall(r'r..n', txt) 236 print(x) 237 # ['rain'] 238 239 3.^ 240 # ^ :Starts with "^hello" 241 x = re.findall(r'^T\w+', txt) # only first word 242 print(x) 243 # ['The'] 244 245 4.$ 246 # $ :Ends with "world$" 247 x = re.findall(r'Spain$', txt) # only last word 248 print(x) 249 # ['Spain'] 250 251 5.* 252 # * :Zero or more occurrences "ai*" 253 x = re.findall(r'ai*', txt) 254 print(x) 255 # ['ai', 'ai'] 256 257 6.+ 258 # + :One or more occurrences "ai+" : (atleast one) 259 x = re.findall(r'ai+', txt) 260 print(x) 261 # ['ai', 'ai'] 262 263 7.? 264 # ? :Zero or one occurrences "ai?" : (atmost one) 265 txt = "The rain in spain at the edge" 266 x = re.findall(r'ai?', txt) # only last word 267 print(x) 268 # ['ai', 'ai', 'a'] 269 270 8.{} 271 # {} :Exactly the specified number of occurrences "ai{2}" 272 text = "They are in the room to coordinate dance on dhoom" 273 x = re.findall(r'\w+o{2}\w+', text) # words with two 'o' 274 print(x) 275 # ['room', 'coordinate', 'dhoom'] 276 277 9.| 278 # | :Either or "falls|stays" 279 x = re.findall('(room|dhoom)', text) 280 print(x) 281 # ['room', 'dhoom'] 282 283 10.() 284 # () :Capture and group 285 x = re.findall(r'(r|dh)(oom)', text) 286 print(x) 287 # [('r', 'oom'), ('dh', 'oom')] 288 289 11.\A 290 # \A :Returns a match if the specified characters are at the beginning of the string 291 x = re.findall(r'\AThey', text) 292 print(x) 293 # ['They'] 294 295 12.\b 296 # \b :Returns a match where the specified characters are at the beginning or at the end of a word 297 x = re.findall(r'\bro\w+', text) 298 print(x) 299 # ['room'] 300 x = re.findall(r'\w+om\b', text) 301 print(x) 302 # ['room', 'dhoom'] 303 304 13.\B 305 # \B :Returns a match where the specified characters are present, but NOT at the beginning (or at the end) of a word 306 x = re.findall(r'\w+\Bom', text) 307 print(x) 308 # ['room', 'dhoom'] 309 310 14.\d 311 # \d :Returns a match where the string contains digits (numbers from 0-9) "\d" 312 text = "The contact nu5ber is +91 9865321474 and flat number 501, street number is 4802 and area is Nanded City" 313 x = re.findall(r'\d{4}', text) # gives the number having 4 digits in it 314 print(x) 315 # ['9865', '3214', '4802'] 316 317 15.\D 318 # \D :Returns a match where the string DOES NOT contain digits "\D" 319 x = re.findall(r'\w+\Dber\b', text) 320 print(x) 321 # ['number', 'number'] 322 323 16.\s 324 # \s :Returns a match where the string contains a white space character "\s" 325 x = re.findall(r'\d+\s\d+', text) 326 print(x) 327 # ['91 9865321474'] 328 329 17.\S 330 # \S :Returns a match where the string DOES NOT contain a white space character "\S" 331 x = re.findall(r'\d+\S\d+', text) 332 print(x) 333 # ['9865321474', '501', '4802'] 334 335 18.\w 336 # \w :Returns a match where the string contains any word characters (a to Z, 0-9, _ ) "\w" 337 x = re.findall(r'\w+\B5b\w+', text) 338 print(x) 339 # ['nu5ber'] 340 341 19.\W 342 # \W :Returns a match where the string DOES NOT contain any word characters "\W" 343 x = re.findall(r'\W\d+', text) 344 print(x) 345 # ['+91', ' 9865321474', ' 501', ' 4802'] 346 347 20.\Z 348 # \Z :Returns a match if the specified characters are at the end of the string "\Z" 349 x = re.findall(r'City\Z', text) 350 print(x) 351 # ['City'] 352 353 21.[abc] 354 text = "The rain in Spain" 355 # [arn] :Returns a match where one of the specified characters (a, r, or n) are present 356 x = re.findall(r'\w+[arn]', text) 357 print(x) 358 # ['rain', 'in', 'Spain'] 359 360 22.[a-c] 361 # [a-n] :Returns a match for any lower case character, alphabetically between a and n 362 x = re.findall(r'[a-n]', text) 363 print(x) 364 # ['h', 'e', 'a', 'i', 'n', 'i', 'n', 'a', 'i', 'n'] 365 366 23.[^a-c] 367 # [^a-n] :Returns a match for any character EXCEPT a to n 368 x = re.findall(r'[^a-n]', text) 369 print(x) 370 # ['T', ' ', 'r', ' ', ' ', 'S', 'p'] 371 372 24.[123] 373 text = "The contact nu5ber is +91 9865321474 and flat number 501, street number is 4802 and area is Nanded City" 374 # [0123] :Returns a match where any of the specified digits (0, 1, 2, or 3) are present 375 x = re.findall(r'[0123]', text) 376 print(x) 377 # ['1', '3', '2', '1', '0', '1', '0', '2'] 378 379 # [0-9] :Returns a match for any digit between 0 and 9 380 x = re.findall(r'[0-9]\d+', text) 381 print(x) 382 # ['91', '9865321474', '501', '4802'] 383 384 # [0-5][0-9] :Returns a match for any two-digit numbers from 00 and 59 385 x = re.findall(r'[0-5][0-9]', text) 386 print(x) 387 # ['53', '21', '47', '50', '48', '02'] 388 389 # [a-zA-Z] :Returns a match for any character alphabetically between a and z, lower case OR upper case 390 x = re.findall(r'[a-zA-Z]\w{4}', text) 391 print(x) 392 # ['conta', 'nu5be', 'numbe', 'stree', 'numbe', 'Nande'] 393 394 25.[+-*/] 395 # [+] :In sets, +, *, ., |, (), $, {} has no special meaning, so [+] means: return a match for any + character in the 396 # string 397 x = re.findall(r'[+]\d+', text) 398 print(x) 399 # ['+91'] 400 401 ------------------------------------------------------------------------------ 402 import re 403 404 # Flags: 405 # re.I | re.IGNORECASE :Ignore case flag 406 # re.M | re.MULTILINE :make begin/end {^, $} consider each line. 407 # re.S | re.DOTALL :make . match newline too. 408 # re.U | re.UNICODE :make {\w, \W, \b, \B} follow Unicode rules. 409 # re.L | re.LOCALE :make {\w, \W, \b, \B} follow locale. 410 # re.X | re.VERBOSE :allow comment in regex. 411 ------------------------------------------------ 412 413 # re.I | re.IGNORECASE :Ignore case flag 414 text = """The contact nu5ber Is +91 9865321474 and Flat number 501, 415 The Street number is 4802 and area is Nanded City 416 My email address is gaurshetty@gmail.""" 417 x = re.findall(r'is', text, re.I) 418 print(x) 419 # ['Is', 'is', 'is'] 420 ------------------------ 421 422 # re.M | re.MULTILINE :make begin/end {^, $} consider each line. 423 x = re.findall(r'^\w+', text, re.M) 424 print(x) 425 # ['The', 'The', 'My'] # first word of each line 426 ------------------------ 427 428 # re.S | re.DOTALL :make . match newline too. 429 # . means any charactor except newline newline also included using this flag 430 text = """Hi this is Gajanan Shetty 431 I live in Pune""" 432 x1 = re.findall(r'.+', text) 433 x2 = re.findall(r'.+', text, re.S) 434 print(x1) 435 print(x2) 436 # ['Hi this is Gajanan Shetty ', 'I live in Pune'] 437 # ['Hi this is Gajanan Shetty \nI live in Pune'] 438 ------------------------ 439 440 # re.U | re.UNICODE :make {\w, \W, \b, \B} follow Unicode rules. 441 # Python 3 uses Unicode for all strings by default, so the flag is not necessary. 442 pattern = re.compile(r'(«)') 443 s = u'«abc «def«' 444 print( re.sub(pattern, r' \1 ', s)) 445 # « abc « def « 446 ------------------------ 447 448 # re.L | re.LOCALE :make {\w, \W, \b, \B} follow locale. 449 # The use of this flag is discouraged as the locale mechanism is very unreliable 450 # it only works with 8-bit locales 451 ------------------------ 452 453 # re.X | re.VERBOSE :allow comment in regex. 454 # Whitespace within the pattern is ignored 455 a = re.compile(r"""\d + # the integral part 456 \. # the decimal point 457 \d * # some fractional digits""", re.X) 458 b = re.compile(r"\d+\.\d*") 459 ------------------------------------------------------------------------------ 460 461 # (?:RE) :non-capturing group 462 txt = 'http://stackoverflow.com/' 463 x = re.search('(https?|ftp)://([^/\r\n]+)(/[^\r\n]*)?', txt) 464 print(x.group()) # http://stackoverflow.com/ 465 print(x.group(1)) # http 466 print(x.group(2)) # stackoverflow.com 467 print(x.group(3)) # / 468 # ------------------------------------------------------------ 469 x = re.search('(?:https?|ftp)://([^/\r\n]+)(/[^\r\n]*)?', txt) 470 print(x.group()) # http://stackoverflow.com/ 471 print(x.group(1)) # stackoverflow.com 472 print(x.group(2)) # / 473 # Here non captured group is https and it is ignored 2nd time 474 475 ------------------------------------------------------------------------------ 476 # (?P<name>pat) :named capture group 477 txt = """Use Phone: 1234567890 or you can also use Landline: 0012345678 478 Use Landline: 0012345678 or you can also use Phone: 1234567890 479 """"" 480 x = re.findall('(?P<phn_num>\d{10})', txt, re.M) 481 print(x) 482 # ['1234567890', '0012345678', '0012345678', '1234567890'] 483 ---------------------------- 484 485 sentence = 'horses are fast' 486 regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)') 487 matched = re.search(regex, sentence) 488 print(matched.groupdict()) 489 # {'animal': 'horses', 'verb': 'are', 'adjective': 'fast'} 490 491 492 ------------------------------------------------------------------------------ 493 # lookarounds 494 -------------- 495 # (?#comment) : comment in pattern 496 txt = 'the python lang the python version then python demo python sample' 497 x = re.findall('t(?#my)he', txt) 498 print(x) 499 # ['the', 'the', 'the'] 500 -------------- 501 # (?=regex) : Positive lookahead 502 # word before the regex(?=word) 503 x = re.findall('python (?=version)', txt) 504 print(x) 505 # ['python '] 506 -------------- 507 # (?!regex) : Negative lookahead 508 # same words other than word before the regex(?=word) 509 x = re.findall('python (?!version)', txt) 510 print(x) 511 # ['python ', 'python ', 'python '] 512 -------------- 513 # (?<=regex) : Positive lookbehind 514 # word after the regex(?=word) 515 x = re.findall('(?<=demo) python', txt) 516 print(x) 517 # [' python'] 518 -------------- 519 # (?<!regex) : Negative lookbehind 520 # same words other than word after the regex(?=word) 521 x = re.findall('(?<!demo) python', txt) 522 print(x) 523 # [' python', ' python', ' python'] 524 -------------- 525 # (?!pat1)(?=pat2) :multiple assertions 526 # match between the two pat 527 x = re.findall('(?<=the) python (?=version)', txt) 528 print(x) 529 # [' python '] 530 ------------------------------------------------------------------------------ 531 532 Some sample Regex: 533 1. Email: 534 regex = [\w\.-]+@[\w\.-]+ 535 2. Indian mobile number 536 regex = ^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[789]\d{9}$ 537 3. US mobile number 538 regex = ^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$ 539 4. Uk mobile number 540 regex = ^(07\d{8,12}|447\d{7,11})$ 541 5. url 542 regex = ((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*) 543 (http|https)://)(www.)?[a-zA-Z0-9@:%._\\+~ #?&//=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*) 544 5. Pancard number 545 regex = \b[A-Z]{5}[0-9]{4}[A-Z]{1}\b 546 6. CVV number 547 regex = ^[0-9]{3,4}$ 548 7. MasterCard number 549 regex=^5[1-5][0-9]{14}|^(222[1-9]|22[3-9]\\d|2[3-6]\\d{2}|27[0-1]\\d|2720)[0-9]{12}$ 550 8. Visa Card number (13 digit or 16 digit) 551 regex = ^4[0-9]{12}(?:[0-9]{3})?$ 552 9. GST (Goods and Services Tax) number 553 regex = ^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$ 554 10. SSN (Social Security Number) 555 regex = ^(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$ 556 11. Indian driving license number 557 regex = ^(([A-Z]{2}[0-9]{2})( )|([A-Z]{2}-[0-9]{2}))((19|20)[0-9][0-9])[0-9]{7}$ 558 12. Valid IMEI Number 559 https://www.geeksforgeeks.org/program-check-valid-imei-number/?ref=rp 560 13. MAC address 561 regex = ^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})|([0-9a-fA-F]{4}\\.[0-9a-fA-F]{4}\\.[0- 9a-fA-F]{4})$ 562 14. HTML tag 563 regex = <("[^"]*"|'[^']*'|[^'">])*> 564 15. domain name 565 regex = ^((?!-)[A-Za-z0-9-]{1, 63}(?<!-)\\.)+[A-Za-z]{2, 6}$ 566 16. IFSC Code 567 regex = ^[A-Z]{4}0[A-Z0-9]{6}$ 568 569 ------------------------------------------------------------------------------ 570 571 # Interview questions on the regular expressions: 572 573 # Why Use Regular Expression? 574 To answer this question, we will look at the various problems faced by us which in turn is solved by using Regular Expressions. 575 Consider the following scenario: 576 1. You have a log file which contains a large sum of data. And from this log file, you wish to fetch only the date and time. As you can know readability of the log file is low upon first glance. Regular Expressions can be used in this case to recognize the patterns and extract the required information easily. 577 2. If you are designing the mailing system in which from row data if want to pick correct email addresses then you have to use regular expression to identify the correct email addresses. 578 3. In some third-party API if you want perform some task on the basis of success massage of API that time, we have to use the regular expression to find the success massages. 579 580 # What Are Regular Expressions? 581 A Regular Expression is used for identifying a search pattern in a text string. It also helps in finding out the correctness of the data and even operations such as finding, replacing and formatting the data is possible using Regular Expressions. 582 The regular expression will help to search the data in faster and reliable manner. 583 584 # What operations You Can Perform with Regular Expressions? 585 There are many operations you can perform by making use of Regular Expressions. 586 1. Finding a word in the string: 587 2. Generating an iterator: 588 3. Matching words with patterns: 589 4. Matching series of range of characters: 590 5. Replacing a string: 591 6. The Backslash Problem: 592 7. Matching a single character: 593 8. Removing Newline Spaces: 594 595 # Practical Use Cases of Regular Expressions? 596 We will be checking out 3 main use-cases which are widely used on a daily basis. Following are the concepts we will be checking out: 597 1. Phone Number Verification 598 2. E-mail Address Verification 599 3. Web Scraping 600 4. Pancard verification 601 5. Aadhar card / Social security Number verification 602 6. Driving License number 603 7. Website extraction 604 8. Mastercard / debit / credit card number 605 9. MAC Address / domain name 606 10. HTML tags 607 608 609 610