Advertisement
eric_han

Regular Expressions - Tested on at least 1 RegEng

Feb 21st, 2019 (edited)
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. End of Line
  2.  
  3. Search for End of Line in Unix, or Old MacOS, or Windows format
  4.  
  5. Equivalent to \R. Use \R in RegEx dialects that have \R. Dialects that I am aware have \R
  6.  
  7. Java
  8. PCRE
  9. Perl
  10. PHP
  11. Ruby
  12.  
  13. Use the ugly circumvention below in dialects that do not have \R. Circumvention seems to work in dialects with and without \R. I have tested circumvention in
  14.  
  15. .NET
  16. Go
  17. Java
  18. JavaScript
  19. PCRE
  20. Perl
  21. PHP
  22. Python
  23. XRegExp
  24.  
  25. And the circumvention is ...
  26.  
  27. (\r|\r?\n)
  28.  
  29.  
  30.  
  31. File with Listed Extension contained in a Line
  32.  
  33. Search for line with file extension. .jpeg used in example.
  34.  
  35. ^.*\bƸExtensionƷ\b.*(?![<>\(\)"]$)
  36.  
  37. Example
  38.  
  39. ^.*\b\.jpe?g\b.*(?![<>\(\)"]$)
  40.  
  41.  
  42.  
  43. File with Listed Extension NOT contained in a Line
  44.  
  45. Search for line WITHOUT any of the (file extensions in a list of file extensions). Example uses CSS|HTML|Several graphics extensions|Fonts.
  46.  
  47. ^(.(?!ƸExtensionsƷ))+$
  48.  
  49. Example
  50.  
  51. ^(.(?!\.(css|html|ico|jpg|js|svg|woff\d?)\b))+$
  52.  
  53.  
  54.  
  55. Hex Dump
  56.  
  57. For a binary display (hex dump) where each Line consists of 3 sections: an offset onto the dump, and 2 data representation sections
  58.  
  59. *( Whitespace ) Offset = 8(hexadecimal digits) Whitespace
  60. DataAsHex = 16( Whitespace 2(hexadecimal digits) ) Whitespace
  61. DataAsChar = 16( Characters )
  62.  
  63. Search for Line excluding DataAsChar section
  64.  
  65. ^\s*[\dA-Fa-f]{8}\s+(?:\s+(?:(?:[\dA-Fa-f]{2})|(?:\.{2}))){16}\s+\B
  66.  
  67.  
  68.  
  69. Line Does Not Contain String
  70.  
  71. Select line that does not contain string ƸNotStringƷ. Use Multiline option.
  72.  
  73. ^(?!ƸNotStringƷ).)+$
  74.  
  75.  
  76.  
  77. Relative Path
  78.  
  79. Search for a path relative to current directory. Path must be in simplest form: first object in relative path must be an object directly under current directory. No Current Directory symbol (.). No Parent Directory symbol (..). Relative path must come immediately after a preceding text line (no intervening blank lines) and be on its own line (end with a newline)
  80.  
  81. [^\r\n](\r|\r?\n)(\w[\w\/]+(\r|\r?\n))
  82.  
  83. Replace starting newline with 3 newlines, adding 2 blank lines
  84.  
  85. $1$1$1$2
  86.  
  87.  
  88.  
  89. UUID aka GUID
  90.  
  91. Search for a Universally Unique Identifier
  92. (UUID) aka a Globally Unique Identifier (GUID). Example eliminates lines with a semicolon anywhere before the UUID.
  93.  
  94. \b[A-F\d]{8}-([A-F\d]{4}-){3}[A-F\d]{12}\b
  95.  
  96. ^[^;]*\b[A-F\d]{8}-([A-F\d]{4}-){3}[A-F\d]{12}\b
  97.  
  98.  
  99.  
  100. URL
  101. Courtesy of Internet Marketing Ninjas (https://www.internetmarketingninjas.com/tools/website-pattern-extractor/)
  102.  
  103. (ht|f)tp(s?)\:\/\/[a-zA-Z0-9\-\._]+(\.[a-zA-Z0-9\-\._]+){2,}(\/?)([a-zA-Z0-9\-\.\?\,'\/\\+&%\$#_]*)?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement