Kawiesh

RegEx Notes

Nov 14th, 2020 (edited)
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. Regular Expression
  2. RegEx is a text string used to describe a search pattern (of data like text etc.).
  3.  
  4. Syntax: /regex/
  5.  
  6. Literal character /thewordyourelookingfor/
  7.  
  8. Flags or modes go after your last /
  9.  
  10. /regex/ stops when it finds a match
  11. /regex/g looks for match til end of data (doesn't give up)
  12. /regex/i makes regexcase insensitive (otherwise it regex is cs)
  13. /regex/m multiline
  14. /regex/ single line. Allows dot to match newline \n
  15.  
  16.  
  17. Metacharacters: \|(){[$.^*+?
  18. These can't be used in literal character search.
  19. If you want to look for any of these 12 char., you have to
  20. escape them by adding a \ in front of them
  21.  
  22. /(Hey)/ will result in an error. Instead you should write /\(hey\)/
  23.  
  24. The dot is a wild character. It will match any character except for a newline. To make the dot also match newline you can use the flag/mode single line(s) /regex/gs
  25.  
  26. Example
  27.  
  28. Test string: Kawiesh kawiesh Kawiesh kaw9esh kaw99sh kAw?e$h
  29.  
  30. /Kawiesh/ Kawiesh ------- ------- ------- ------- -------
  31. /Kawiesh/g Kawiesh ------- Kawiesh ------- ------- -------
  32. /Kawiesh/gi Kawiesh kawiesh Kawiesh ------- ------- -------
  33. /Kaw.esh/gi Kawiesh kawiesh Kawiesh kaw9esh ------- -------
  34.  
  35. Dot is a place holder for only one character.
  36.  
  37. Test string:
  38. Kaw
  39. Iesh
  40.  
  41. /kaw.iesh/gi no match
  42. /kaw.iesh/gis match!
  43.  
  44.  
  45. ....... Other metacharacters.......
  46.  
  47. \d matches all digits (0-9)
  48. \w matches all letters (lowercase or uppercase), all digits and underscore
  49. \s matches all white spaces (e.g.space, tab, new line)
  50.  
  51. To match the opposite/inverse match, use capital letters
  52. E.g \D will match every character except digits.
  53.  
Advertisement
Add Comment
Please, Sign In to add comment