RegexBuddy Library{^.{%SKIPAMOUNT%}(%REGEX%)?Columns: Match a regex starting at a specific column on a line. %SKIPAMOUNT%5Number of characters to skip at the start of the line10%REGEX%.The regex to be matched at column skipamount+1regex$^.{%SKIPAMOUNT%}(.{%CAPTUREAMOUNT%})Columns: Range of characters on a line, captured into backreference 1 Iterate over all matches to extract a column of text from a file E.g. to grab the characters in colums 8..10, set SKIPAMOUNT to 7, and CAPTUREAMOUNT to 3 %SKIPAMOUNT%5Number of characters to skip at the start of the line10%CAPTUREAMOUNT%Number of characters to capture10i^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$Credit card: All major cards Checks if a series of digits is possibly a valid credit card number. Use this regex to speed up credit card transactions by filtering out obviously invalid card numbers before sending the order to the credit card processor.^3[47][0-9]{13}$Credit card: American Express Checks if a series of digits is possibly a valid American Express credit card number. Use this regex to speed up credit card transactions by filtering out obviously invalid card numbers before sending the order to the credit card processor. ^3(?:0[0-5]|[68][0-9])[0-9]{11}$Credit card: Diners Club Checks if a series of digits is possibly a valid Diners Club credit card number. Use this regex to speed up credit card transactions by filtering out obviously invalid card numbers before sending the order to the credit card processor.^6011[0-9]{14}$Credit card: Discover Checks if a series of digits is possibly a valid Discover credit card number. Use this regex to speed up credit card transactions by filtering out obviously invalid card numbers before sending the order to the credit card processor.^5[1-5][0-9]{14}$Credit card: MasterCard Checks if a series of digits is possibly a valid MasterCard credit card number. Use this regex to speed up credit card transactions by filtering out obviously invalid card numbers before sending the order to the credit card processor.[^0-9]+Credit card: remove non-digits Before using one of the other regular expressions in this library to test credit card numbers, use this regular expression to remove non-digits (particularly dashes and spaces) from the input string.^4[0-9]{12}(?:[0-9]{3})?$Credit card: Visa Checks if a series of digits is possibly a valid Visa credit card number. Use this regex to speed up credit card transactions by filtering out obviously invalid card numbers before sending the order to the credit card processor.("[^"\r\n]*")?,(?![^",\r\n]*"$)\1\tiCSV: Change delimiter Changes the delimiter from a comma into a tab. The capturing group makes sure delimiters between double quotes are ignored. The negative lookahead makes sure delimiters between double quotes in the last field are ignored. Replace both commas in the regex and the tab at the end of the replacement to convert between any two delimiters.I^("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*)$CSV: Complete row, all fields. Match complete rows in a comma-delimited file that has 3 fields per row, capturing each field into a backreference. To match CSV rows with more or fewer fields, simply duplicate or delete the capturing groups.^(?:(?:"[^"\r\n]*"|[^,\r\n]*),){%SKIPLEAD%}("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*)(?:(?:"[^"\r\n]*"|[^,\r\n]*),){%SKIPTRAIL%}$BCSV: Complete row, certain fields. Set %SKIPLEAD% to the number of fields you want to skip at the start, and %SKIPTRAIL% to the number of fields you want to ignore at the end of each row. This regex captures 3 fields into backreferences. To capture more or fewer fields, simply duplicate or delete the capturing groups. %SKIPLEAD%'Fields to skip at the start of each row1 %SKIPTRAIL%'Fields to ignore at the end of each row1r^(?:(?:"[^"\r\n]*"|[^,\r\n]*),){%SKIPLEAD%}("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*)CSV: Partial row, certain fields Match the first SKIPLEAD+3 fields of each rows in a comma-delimited file that has SKIPLEAD+3 or more fields per row. The 3 fields after SKIPLEAD are each captured into a backreference. All other fields are ignored. Rows that have less than SKIPLEAD+3 fields are skipped. To capture more or fewer fields, simply duplicate or delete the capturing groups. %SKIPLEAD%'Fields to skip at the start of each row1H^("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*)bCSV: Partial row, leading fields Match the first 3 fields of each rows in a comma-delimited file that has 3 or more fields per row. The first 3 fields are each captured into a backreference. All other fields are ignored. Rows that have less than 3 fields are skipped. To capture more or fewer fields, simply duplicate or delete the capturing groups.J^("[^"\r\n]*"|[^,\r\n]*),("[^"\r\n]*"|[^,\r\n]*)?,("[^"\r\n]*"|[^,\r\n]*)?CSV: Partial row, variable leading fields Match the first 3 fields of each rows in a comma-delimited file. The first 3 fields are each captured into a backreference. All other fields are ignored. If a row has fewer than 3 field, some of the backreferences will remain empty. To capture more or fewer fields, simply duplicate or delete the capturing groups. The question mark after each group makes that group optional.I\b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}\bDate d/m/yy and dd/mm/yyyy 1/1/00 through 31/12/99 and 01/01/1900 through 31/12/2099 Matches invalid dates such as February 31st Accepts dashes, spaces, forward slashes and dots as date separatorsB(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}Date dd/mm/yyyy 01/01/1900 through 31/12/2099 Matches invalid dates such as February 31st Accepts dashes, spaces, forward slashes and dots as date separatorsI\b(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}\bDate m/d/y and mm/dd/yyyy 1/1/99 through 12/31/99 and 01/01/1900 through 12/31/2099 Matches invalid dates such as February 31st Accepts dashes, spaces, forward slashes and dots as date separatorsB(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}Date mm/dd/yyyy 01/01/1900 through 12/31/2099 Matches invalid dates such as February 31st Accepts dashes, spaces, forward slashes and dots as date separatorsI\b(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])\bDate yy-m-d or yyyy-mm-dd 00-1-1 through 99-12-31 and 1900-01-01 through 2099-12-31 Matches invalid dates such as February 31st Accepts dashes, spaces, forward slashes and dots as date separatorsB(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])Date yyyy-mm-dd 1900-01-01 through 2099-12-31 Matches invalid dates such as February 31st Accepts dashes, spaces, forward slashes and dots as date separators)\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\bEmail address Use this version to seek out email addresses in random documents and texts. Does not match email addresses using an IP address instead of a domain name. Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum. Including these increases the risk of false positives when applying the regex to random documents. Requires the "case insensitive" option to be ON.'^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$MEmail address (anchored) Use this anchored version to check if a valid email address was entered. Does not match email addresses using an IP address instead of a domain name. Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum. Requires the "case insensitive" option to be ON.a^[A-Z0-9._%-]+@[A-Z0-9-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$Email address (specific TLDs) Does not match email addresses using an IP address instead of a domain name. Matches all country code top level domains, and specific common top level domains. Requires the "case insensitive" option to be ON.7\b(?:mailto:)?([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})\b<a href="mailto:\1">\0</a>%Email address: Replace with HTML link(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)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\[\] \x00-\x1F]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \x00-\x1F]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*))*)?;\s*)AEmail address: RFC822 This beast of a regular expression matches an email address that adheres to the RFC 822 standard. Using this regular expression in actual applications is NOT recommended. It is shown to illustrate that with regular expressions there's always a trade-off between what's exact and what's practical. <!--.*?--> HTML commentP<html>.*?<head>.*?<title>.*?</title>.*?</head>.*?<body[^>]*>.*?</body>.*?</html>~HTML file Matches a complete HTML file. Place round brackets around the .*? parts you want to extract from the file. Performance will be terrible on HTML files that miss some of the tags (and thus won't be matched by this regular expression). Use the atomic version instead when your search includes such files (the atomic version will also fail invalid files, but much faster).h<html>(?>.*?<head>)(?>.*?<title>)(?>.*?</title>)(?>.*?</head>)(?>.*?<body[^>]*>)(?>.*?</body>).*?</html>HTML file (atomic) Matches a complete HTML file. Place round brackets around the .*? parts you want to extract from the file. Atomic grouping maintains the regular expression's performance on invalid HTML files.!<([A-Z][A-Z0-9]*)[^>]*>(.*?)</\1>HTML tag Matches the opening and closing pair of whichever HTML tag comes next. The name of the tag is stored into the first capturing group. The text between the tags is stored into the second capturing group.<%TAG%[^>]*>(.*?)</%TAG%>HTML tag Matches the opening and closing pair of a specific HTML tag. Anything between the tags is stored into the first capturing group. Does NOT properly match tags nested inside themselves.%TAG%The HTML tag you want to matchHTML</?[a-z][a-z0-9]*[^<>]*>HHTML tag Matches any opening or closing HTML tag, without its contents.:\b([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\bIP address Matches 0.0.0.0 through 999.999.999.999 Use this fast and simple regex if you know the data does not contain invalid IP addresses. Each of the 4 numbers is stored into a capturing group, so you can access them for further processing.!\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\bIP address Matches 0.0.0.0 through 999.999.999.999 Use this fast and simple regex if you know the data does not contain invalid IP addresses, and you don't need access to the individual IP numbers.]\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\bIP address Matches 0.0.0.0 through 255.255.255.255 Use this regex to match IP numbers with accurracy, without access to the individual IP numbers.\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\bIP address Matches 0.0.0.0 through 255.255.255.255 Use this regex to match IP numbers with accurracy. Each of the 4 numbers is stored into a capturing group, so you can access them for further processing.^$`Lines: Absolutely blank (no whitespace) Regex match does not include line break after the line.$ something$Lines: Append something to each line^[ \t]*$^Lines: Blank (may contain whitespace) Regex match does not include line break after the line.^(?=.*?%ONE%)(?=.*?%TWO%).*$Lines: Complete line matched by several unrelated regular expressions, anywhere on the line. Explanation: Right after the anchor, two sets of lookahead scan the entire line for a regular expression. If one of the lookaheads fails, the overall match fails. If all three succeed, the final .* matches the entire line. To add additional requirements, simply add additional lookaheads after the anchor. For efficiency, specify them from least likely to match to most likely to match. That allows the overall regex to fail faster.%ONE%First requirementone%TWO%Second requirementtwo^(?:(?!%REGEX%).)*$\r?\n?Lines: Complete line NOT matched by the regular expression %REGEX% Explanation: Observe that the negative lookahead and the dot are repeated together. This makes sure we test that %REGEX% fails at EVERY position in the string, and not just at any particular position. Tip: use alternation in %REGEX% to match a line that does not meet any of several requirements. E.g. set %REGEX% to "one|two" (without the quotes), and the overall regular expression will match any line that does not contain either (or both) "one" or "two".%REGEX%0The regular expression the line should NOT match%REGEX%^.*(%REGEX%).*$Lines: Complete line partially matched by a regex Substitute %REGEX% with the regular expression you want to search for. The overall regular expression will then completely match each line that is partially matched by the regular expression you substituted %REGEX% with.%REGEX%;The regular expression that should partially match the lineregex^(?:(?!%REGEX%).)*$Lines: Complete line, including terminating line break, NOT matched by the regular expression %REGEX% Explanation: Observe that the negative lookahead and the dot are repeated together. This makes sure we test that %REGEX% fails at EVERY position in the string, and not just at any particular position. Tip: use alternation in %REGEX% to match a line that does not meet any of several requirements. E.g. set %REGEX% to "one|two" (without the quotes), and the overall regular expression will match any line that does not contain either (or both) "one" or "two". You could use this regex in a search-and-replace operation in a text editor to delete or substitute complete lines.%REGEX%0The regular expression the line should NOT match%REGEX%^.*(%REGEX%).*$\r?\n?Lines: Complete line, including terminating line break, partially matched by a regex Substitute %REGEX% with the regular expression you want to search for. The overall regular expression will then completely match each line that is partially matched by the regular expression you substituted %REGEX% with. You could use this regex in a search-and-replace operation in a text editor to delete or substitute complete lines.%REGEX%;The regular expression that should partially match the lineregex^\r?\nULines: Delete absolutely blank lines Regex match includes line break after the line. ^[ \t]*$\r?\nJLines: Delete blank lines Regex match includes line break after the line.^(.*)(\r?\n\1)+$\1Lines: Delete duplicate lines This regex matches two or more lines, each identical to the first line. It deletes all of them, except the first.^(.*)(\r?\n\1)+$_Lines: Duplicate lines This regex matches two or more lines, each identical to the first line.^ something%Lines: Prepend something to each line^(.*)(%REGEX%).*$$1$2xLines: Truncate a line after a regex match. The regex you specify is guaranteed to match only once on each line. If the original regex you specified should match more than once, the line will be truncated after the last match. Explanation: This works because the first dot-star is greedy. It will match the complete line, and then backtrack until %REGEX% can be matched.%REGEX%;The regular expression that should partially match the line%REGEX% (%REGEX%).*$$1Lines: Truncate a line after a regex match. If the regex matches more than once on the same line, everything after the first match is deleted.%REGEX%;The regular expression that should partially match the line%REGEX%^.*(%REGEX%)(.*)$$1$2Lines: Truncate a line before a regex match. The regex you specify is guaranteed to match only once on each line. If the original regex you specified should match more than once, the line will be truncated before the first match.%REGEX%;The regular expression that should partially match the line%REGEX% ^.*(%REGEX%)$1Lines: Truncate a line before a regex match. If the regex matches more than once on the same line, everything before the last match is deleted.%REGEX%;The regular expression that should partially match the line%REGEX%^.*(%REGEX%).*$$1Lines: Truncate a line before and after a regex match. This will delete everything from the line not matched by the regular expression.%REGEX%;The regular expression that should partially match the line%REGEX%^(?<client>\S+)\s+(?<auth>\S+\s+\S+)\s+\[(?<datetime>[^]]+)\]\s+"(?:GET|POST|HEAD) (?<file>[^ ?"]+?\.html?)\??(?<parameters>[^ ?"]+)? HTTP/[0-9.]+"\s+(?<status>[0-9]+)\s+(?<size>[-0-9]+)\s+"(?<referrer>[^"]*)"\s+"(?<useragent>[^"]*)"$Logs: Apache web server Successful hits to HTML files only. Useful for counting the number of page views. When gathering statistics about user agents and referrers, it often makes sense to look at hits to HTML files only. Captures each item into a named capturing group. Works as it is with .NET, and after conversion by RegexBuddy on the Use page with Python, PHP/preg and PCRE.^(?<client>\S+)\s+(?<auth>\S+\s+\S+)\s+\[(?<datetime>[^]]+)\]\s+"(?:GET|POST|HEAD) (?<file>[^ ?"]+)\??(?<parameters>[^ ?"]+)? HTTP/[0-9.]+"\s+404\s+(?<size>[-0-9]+)\s+"(?<referrer>[^"]*)"\s+"(?<useragent>[^"]*)"$Logs: Apache web server 404 errors only Captures each item into a named capturing group. Works as it is with .NET, and after conversion by RegexBuddy on the Use page with Python, PHP/preg and PCRE.^(?<client>\S+)\s+(?<auth>\S+\s+\S+)\s+\[(?<datetime>[^]]+)\]\s+"(?:GET|POST|HEAD) (?<file>[^ ?"]+)\??(?<parameters>[^ ?"]+)? HTTP/[0-9.]+"\s+(?<status>[0-9]+)\s+(?<size>[-0-9]+)\s+"(?<referrer>[^"]*)"\s+"(?<useragent>[^"]*)"$^Logs: Apache web server Matches any single line from Apache's access logs, capturing each item into a named capturing group. Works as it is with .NET, and after conversion by RegexBuddy on the Use page with Python, PHP/preg and PCRE. If you are not interested in certain items, change the capturing groups into non-capturing groups for efficiency. ^((?#client IP or domain name)\S+)\s+((?#basic authentication)\S+\s+\S+)\s+\[((?#date and time)[^]]+)\]\s+"(?:GET|POST|HEAD) ((?#file)[^ ?"]+)\??((?#parameters)[^ ?"]+)? HTTP/[0-9.]+"\s+(?#status code)404\s+((?#bytes transferred)[-0-9]+)\s+"((?#referrer)[^"]*)"\s+"((?#user agent)[^"]*)"$(Logs: Apache web server 404 errors only)^((?#client IP or domain name)\S+)\s+((?#basic authentication)\S+\s+\S+)\s+\[((?#date and time)[^]]+)\]\s+"(?:GET|POST|HEAD) ((?#file)/[^ ?"]+?\.html?)\??((?#parameters)[^ ?"]+)? HTTP/[0-9.]+"\s+(?#status code)200\s+((?#bytes transferred)[-0-9]+)\s+"((?#referrer)[^"]*)"\s+"((?#user agent)[^"]*)"$Logs: Apache web server Successful hits to HTML files only. Useful for counting the number of page views. When gathering statistics about user agents and referrers, it often makes sense to look at hits to HTML files only.%^((?#client IP or domain name)\S+)\s+((?#basic authentication)\S+\s+\S+)\s+\[((?#date and time)[^]]+)\]\s+"(?:GET|POST|HEAD) ((?#file)[^ ?"]+)\??((?#parameters)[^ ?"]+)? HTTP/[0-9.]+"\s+((?#status code)[0-9]+)\s+((?#bytes transferred)[-0-9]+)\s+"((?#referrer)[^"]*)"\s+"((?#user agent)[^"]*)"$Logs: Apache web server Matches any single line from Apache's access logs, capturing each item into a backreference. If you are not interested in certain items, change the capturing groups into non-capturing groups for efficiency.,\b[0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?\b,SNumber: Currency amount Optional thousands separators; optional two-digit fraction'\b[0-9]{1,3}(?:,?[0-9]{3})*\.[0-9]{2}\b,TNumber: Currency amount Optional thousands separators; mandatory two-digit fraction[-+]?\b[0-9]+(\.[0-9]+)?\byNumber: floating point Matches an integer or a floating point number with mandatory integer part. The sign is optional.[-+]?\b[0-9]*\.?[0-9]+\bxNumber: floating point Matches an integer or a floating point number with optional integer part. The sign is optional.\b0[xX][0-9a-fA-F]+\bNumber: hexadecimal (C-style)$(?<=[0-9])(?=(?:[0-9]{3})+(?![0-9])),NNumber: Insert thousands separators Replaces 123456789.00 with 123,456,789.00\b\d+\bNumber: integer [-+]?\b\d+\b"Number: integer with optional sign?[-+]?(?:\b[0-9]+(?:\.[0-9]*)?|\.[0-9]+\b)(?:[eE][-+]?[0-9]+\b)?Number: scientific floating point Matches an integer or a floating point number. Integer and fractional parts are both optional. Both the sign and exponent are optional.,[-+]?\b[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?\bNumber: scientific floating point Matches an integer or a floating point number with optional integer part. Both the sign and exponent are optional. ]\A(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])[-_a-zA-Z0-9]{6,}\zPassword complexity Tests if the input consists of 6 or more letters, digits, underscores and hyphens. The input must contain at least one upper case ltter, one lower case letter and one digit.R\A(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])\S{6,}\zPassword complexity Tests if the input consists of 6 or more characters. The input must contain at least one upper case ltter, one lower case letter and one digit.\b[a-z]:\\[^/:*?"<>|\r\n]* Path: WindowsP\b((?#drive)[a-z]):\\((?#folder)[^/:*?"<>|\r\n]*\\)?((?#file)[^\\/:*?"<>|\r\n]*)OPath: Windows Different elements of the path are captured into backreferences.5(?:(?#drive)\b[a-z]:|\\\\[a-z0-9]+)\\[^/:*?"<>|\r\n]*Path: Windows or UNC^((?#drive)\b[a-z]:|\\\\[a-z0-9]+)\\((?#folder)[^/:*?"<>|\r\n]*\\)?((?#file)[^\\/:*?"<>|\r\n]*)VPath: Windows or UNC Different elements of the path are captured into backreferences.0\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4}) (\1) \2-\3Phone Number (North America) Matches 3334445555, 333.444.5555, 333-444-5555, 333 444 5555, (333) 444 5555 and all combinations thereof. Replaces all those with (333) 444-5555*\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4} (\1) \2-\3Phone Number (North America) Matches 3334445555, 333.444.5555, 333-444-5555, 333 444 5555, (333) 444 5555 and all combinations thereof.2\b[ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9]\bPostal code (Canada)5\b[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}\bPostal code (UK)#.*$OProgramming: # comment Single-line comment started by # anywhere on the line^\s*#.*$uProgramming: # preprocessor statement Started by # at the start of the line, possibly preceded by some whitespace. /\*.*?\*/Programming: /* comment */ Does not match nested comments. Most languages, including C, Java, C#, etc. do not allow comments to be nested. I.e. the first */ closes the comment.//.*$QProgramming: // comment Single-line comment started by // anywhere on the line\\(.)\1OProgramming: Remove escapes Remove backslashes used to escape other characters"[^"\\]*(?:\\.[^"\\]*)*"xProgramming: String Quotes may appear in the string when escaped with a backslash. The string may span multiple lines. "[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*"{Programming: String Quotes may appear in the string when escaped with a backslash. The string cannot span multiple lines. "[^"\r\n]*"aProgramming: String Quotes may not appear in the string. The string cannot span multiple lines.[\x84\x93\x94]"Quotes: Replace smart double quotes with straight double quotes. ANSI version for use with 8-bit regex engines and the Windows code page 1252.&[\u201C\u201D\u201E\u201F\u2033\u2036]"uQuotes: Replace smart double quotes with straight double quotes. Unicode version for use with Unicode regex engines.&[\u2018\u2019\u201A\u201B\u2032\u2035]'Quotes: Replace smart single quotes and apostrophes with straight single quotes. Unicode version for use with Unicode regex engines.[\x82\x91\x92]'Quotes: Replace smart single quotes and apostrophes with straight single quotes. ANSI version for use with 8-bit regex engines and the Windows code page 1252.\b'\b ;Quotes: Replace straight apostrophes with smart apostrophes!\B"\b([^"\x84\x93\x94\r\n]+)\b"\B \1 Quotes: Replace straight double quotes with smart double quotes. ANSI version for use with 8-bit regex engines and the Windows code page 1252.9\B"\b([^"\u201C\u201D\u201E\u201F\u2033\u2036\r\n]+)\b"\B \1 uQuotes: Replace straight double quotes with smart double quotes. Unicode version for use with Unicode regex engines.9\B'\b([^'\u2018\u2019\u201A\u201B\u2032\u2035\r\n]+)\b'\B \1 uQuotes: Replace straight single quotes with smart single quotes. Unicode version for use with Unicode regex engines.!\B'\b([^'\x82\x91\x92\r\n]+)\b'\B \1 Quotes: Replace straight single quotes with smart single quotes. ANSI version for use with 8-bit regex engines and the Windows code page 1252.[][{}()*+?.\\]\\\0aRegex: Escape metacharacters Place a backslash in front of the regular expression metacharacters\b[0-9]{3}-[0-9]{2}-[0-9]{4}\bSocial security number (US)\s+\z@Trim whitespace (including line breaks) at the end of the string \A\s+|\s+\zNTrim whitespace (including line breaks) at the start and the end of the string\A\s+BTrim whitespace (including line breaks) at the start of the string[ \t]+$'Trim whitespace at the end of each line^[ \t]+|[ \t]+$5Trim whitespace at the start and the end of each line^[ \t]+)Trim whitespace at the start of each line\b((?#protocol)https?|ftp)://((?#domain)[-A-Z0-9.]+)((?#file)/[-A-Z0-9+&@#/%=~_|!:,.;]*)?((?#parameters)\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?tURL: Different URL parts Protocol, domain name, page and CGI parameters are captured into backreferenes 1 through 4\b(?<protocol>https?|ftp)://(?<domain>[-A-Z0-9.]+)(?<file>/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(?<parameters>\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?URL: Different URL parts Protocol, domain name, page and CGI parameters are captured into named capturing groups. Works as it is with .NET, and after conversion by RegexBuddy on the Use page with Python, PHP/preg and PCRE.C\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]URL: Find in full text The final character class makes sure that if an URL is part of some text, punctuation such as a comma or full stop after the URL is not interpreted as part of the URL.C\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]<a href="\0">\0</a>!URL: Replace URLs with HTML linksH((I|you|we|they)\s+love|s?he\s+loves)\s*reg(ular expressions?|ex(p|es)?)We love regular expressions\b(?:(?!%REGEX%)\w)+\b@Words: Any word NOT matching a particular regex This regex will match all words that cannot be matched by %REGEX%. Explanation: Observe that the negative lookahead and the \w+ are repeated together. This makes sure we test that %REGEX% fails at EVERY position in the word, and not just at any particular position.%REGEX%0The regular expression the word should NOT matchexclude\b(\w+)(?:\s+\1\b)+\1yWords: Delete repeated words Find any word that occurs twice or more in a row. Delete all occurrences except the first.A\b(?:word1(?:\W+\w+){1,3}\W+word2|word2(?:\W+\w+){1,3}\W+word1)\bkWords: Near, any order Matches word1 and word2, or vice versa, separated by at least 1 and at most 3 words<\b(word1|word2|word3)(?:\W+\w+){1,6}\W+(word1|word2|word3)\b}Words: Near, list Matches any pair of words out of the list word1, word2, word3, separated by at least 1 and at most 6 words \bword1(?:\W+\w+){1,3}\W+word2\biWords: Near, ordered Matches word1 and word2, in that order, separated by at least 1 and at most 3 words\b(\w+)\s+\1\bHWords: Repeated words Find any word that occurs twice or more in a row. \b%WORD%\bWords: Whole word%WORD%The word you are looking forword\b(?:word1|word2|word3)\b7Words: Whole word Match one of the words from the list \b%WORD%\s*$KWords: Whole word at the end of a line Whitespace permitted after the word%WORD%The word you are looking forword \b%WORD%$&Words: Whole word at the end of a line%WORD%The word you are looking forword ^%WORD%\b(Words: Whole word at the start of a line%WORD%The word you are looking forword ^\s*%WORD%\bNWords: Whole word at the start of a line Whitespace permitted before the word%WORD%The word you are looking forword\b[0-9]{5}(?:-[0-9]{4})?\b ZIP code (US)