The Ready to use Regex repository is a comprehensive collection of ready-to-use regular expressions (regex) for various common tasks. This repository aims to provide a valuable resource for developers, data analysts, and anyone working with text data, by offering a wide range of regex patterns specifically designed for tasks such as email validation, phone number parsing, credit card number recognition, and more.
- Regex:
\s+
- Validating phone numbers in different formats-
- Regex pattern:
^(?:\+\d{1,3}\s?)?(?:\(\d{1,4}\)\s?)?(?:\d{1,4}[\s-])?\d{1,10}$
- Example formats:
- +1 (123) 456-7890
- 5551234567
- (999) 9999-9999
- +1 5551234567
- +1 (416) 555 7890
- +33 123456789
- +91 9876543210
- Regex pattern:
-
Normalizing phone numbers to a consistent format:
- Regex pattern:
^(\+?\d{1,3}\s?)?(\(?\d{1,4}\)?\s?)?(\d{1,})[-\s]?(\d{1,})$
- Example formats:
- +1 (123) 456-7890 (normalizes to +11234567890)
- 555 123 4567 (normalizes to 5551234567)
- +55 (11) 98765-4321 (normalizes to 5511987654321)
- +86 10 1234 5678 (normalizes to +861012345678
- +91 98765 43210 (normalizes to +919876543210)
- Regex pattern:
- Validating email addresses:
- Regex pattern:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
- Example formats:
- Regex pattern:
- Extracting domain names from email addresses:
- Regex pattern:
@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
- Example formats:
- john.doe@example.com (extracts example.com)
- jane_smith123@gmail.com (extracts gmail.com)
- Regex pattern:
- Validating URLs:
- Regex pattern:
https?:\/\/[\w.-]+\.[\w.-]+[^\s]*
- Example formats:
- Regex pattern:
- Extracting different components of a URL(https://www.example.com/path/file.html?param1=value1¶m2=value2):
- Extracting protocol:
- Extracting domain:
- Regex pattern:
(https?):\/\/([a-zA-Z0-9.-]+)
- Example format:
- Regex pattern:
- Extracting path:
- Extracting query parameters:
- Regex pattern:
(https?):\/\/[a-zA-Z0-9.-]+(\/[^?\s]*)?(\?[^#\s]*)?$
- Example format:
- ?param1=value1¶m2=value2
- Extracted Groups:
- https
- /path/file.html
- ?param1=value1¶m2=value2
- Regex pattern:
-
Extracting values from structured data formats:
- To extract values from XML:
<(.*?)>([^<]+)<\/\1>
- Example:
- Extract values between XML tags, such as
# data <person> <name>John Doe</name> <age>25</age> <email>johndoe@example.com</email> </person> # Expected Results name John Doe age 25 email johndoe@example.com
- Example:
- To extract values from XML:
- Validating credit card numbers:
- Extracting credit card expiration dates:
- Matching CVV (Card Verification Value) codes:
- Regex Pattern:
^\d{3,4}$
- Example CVV Codes:
- 123
- 7890
- 4321
- Example CVV Codes:
- Regex Pattern: