Regular Expressions

From The Travis van der Font Wiki
Jump to: navigation, search

This entire page is completely experimental (including the codes within below chart) and is subject to change (from improvements) over time.

Method Code Description Diagram
BITCOIN_ADDRESS [13][a-km-zA-HJ-NP-Z1-9]{25,34} Finds all bitcoin addresses
CREDIT_CARD (?:(?:(?:\d{4}[- ]?){3}\d{4}|\d{15,16})) Finds all credit card numbers
DATE (?i)(?:[0-3]?\d(?:st|nd|rd|th)?\s+(?:of\s+)?(?:jan\.?|january|feb\.?|february|mar\.?|march|apr\.?|april|may|jun\.?|june|jul\.?|july|aug\.?|august|sep\.?|september|oct\.?|october|nov\.?|november|dec\.?|december)|(?:jan\.?|january|feb\.?|february|mar\.?|march|apr\.?|april|may|jun\.?|june|jul\.?|july|aug\.?|august|sep\.?|september|oct\.?|october|nov\.?|november|dec\.?|december)\s+[0-3]?\d(?:st|nd|rd|th)?)(?:\,)?\s*(?:\d{4})?|[0-3]?\d[-\./][0-3]?\d[-\./]\d{2,4} Finds all date strings (in English)
DATE_YYY_MM_DD /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/ Match YYYY-MM-DD string
EXACT ^715$ Match fields with '715' only and exactly
GIT_REPO ((git|ssh|http(s)?)|([email protected][\w\.]+))(:(\/\/)?)([\w\[email protected]\:/\-~]+)(\.git)(\/)? Finds all GIT repository addresses which have protocol prefix
GUID [0-9a-fA-F]{8}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{12} Finds all Globally Unique Identifier (GUID) strings
HEX_COLOR (?:#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})) Finds all hex color values
MAC_ADDRESS (([a-fA-F0-9]{2}[:-]){5}([a-fA-F0-9]{2})) Finds all MAC addresses
MASTER_CARD 5[1-5]\d{2}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4} Finds all MasterCard credit card numbers
MD5_HEX [0-9a-fA-F]{32}
NOT_KNOWN_PORT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|:))|(?:(?:[0-9A-Fa-f]{1,4}:){1}(?:(?:(?::[0-9A-Fa-f]{1,4}){1,6})|(?:(?::[0-9A-Fa-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9A-Fa-f]{1,4}){1,7})|(?:(?::[0-9A-Fa-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*
Finds all IPv6 addresses
IBAN [A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z\d]?){0,16} Finds all IBAN strings
ISBN10 (?:[\d]-?){9}[\dxX] Finds all ISBN10 strings
ISBN13 (?:[\d]-?){12}[\dxX] Finds all ISBN13 strings
IS_SHA1 /^[0-9a-f]{40}$/i 40 character hexadecimal string Regex - IS SHA1 - v1.png
IS_VALID_PASSWORD ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20}) 6-20 characters string with at least one digit, one upper case letter, one lower case letter and one special symbol (“@#$%”)
SHA1_HEX [0-9a-fA-F]{40} Finds all SHA1 hex strings
SHA256_HEX [0-9a-fA-F]{64} Finds all SHA256 hex strings
TIME (?i)\d{1,2}:\d{2} ?(?:[ap]\.?m\.?)?|\d[ap]\.?m\.? Finds all time strings (in English)
USA_STREET_ADDRESS \d{1,4} [\w\s]{1,20}(?:street|st|avenue|ave|road|rd|highway|hwy|square|sq|trail|trl|drive|dr|court|ct|park|parkway|pkwy|circle|cir|boulevard|blvd)\W? Finds all street addresses (in the USA)
USA_PO_BOX (?i)P\.? ?O\.? Box \d+ Finds all P.O. Box strings (in the USA)
USA_SOCIAL_SECURITY (?:\d{3}-\d{2}-\d{4}) Finds all USA SSN strings
USA_ZIPCODE \b\d{5}(?:[-\s]\d{4})?\b Finds all zip codes (in the USA)
USD_PRICE [$]\s?[+-]?[0-9]{1,3}(?:(?:,?[0-9]{3}))*(?:\.[0-9]{1,2})? Finds all price strings (for US Doolar)
VISA_CARD 4\d{3}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4} Finds all VISA credit card numbers
WEB_LINK (?:(?:https?:\/\/)?(?:[a-z0-9.\-]+|www|[a-z0-9.\-])[.](?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s!()\[\]{};:\'".,<>?]))

Additional Sources:

https://www.freeformatter.com/regex-tester.html

IS_SHA1
/        Opening Delimiter

^        Start Of String Anchor

[0-9a-f] Any of the following characters: 0123456789abcdef

{40}     Repeated 40 times

$        End Of String Anchor

/        Closing Delimiter

i        Modifier: Case-Insensitive Search

IS_VALID_PASSWORD
(               # Start of group
  (?=.*\d)      # must contains one digit from 0-9
  (?=.*[a-z])	# must contains one lowercase characters
  (?=.*[A-Z])   # must contains one uppercase characters
  (?=.*[@#$%])  # must contains one special symbols in the list "@#$%"
   .            # match anything with previous condition checking
  {6,20}        # length at least 6 characters and maximum of 20	
)               # End of group

Regular Expression Visualizer

Additional Reference(s)