An open API service indexing awesome lists of open source software.

https://github.com/kunal00000/regular-expressions_regex

The ReadyRegex repository is a comprehensive collection of ready-to-use regular expressions (regex) for various common tasks.
https://github.com/kunal00000/regular-expressions_regex

regex regex-match regex-validator regexp

Last synced: 3 months ago
JSON representation

The ReadyRegex repository is a comprehensive collection of ready-to-use regular expressions (regex) for various common tasks.

Awesome Lists containing this project

README

        

# Regular-Expressions_regex
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.

1. [Whitespaces](#whitespace)
2. [Phone Number (various formats)](#phone-numbers)
1. [Validating phone numbers in various formats](#validate-phone)
2. [Normalizing phone numbers to a consistent format:](#normalise-phone)
3. [Email Addresses](#email-addresses)
1. [Validating email addresses:](#validate-email)
2. [Extracting domain names from email addresses:](#extract-domain)
4. [URLs](#urls)
1. [Validating URLs:](#validate-url)
2. [Extract Protocol](#extract-protocol)
3. [Extract Domain](#extract-domain)
4. [Extract Path](#extract-path)
5. [Extract Query Parameters](#extract-params)
5. [Data Extraction](#data-extraction)
1. [To extract dates:](#extract-dates)
2. [To extract time:](#extract-times)
3. [To extract address:](#extract-address)
4. [To extract values from XML:](#extract-xml)
6. [Credit Card](#credit-card)
1. [Validating credit card numbers:](#validate-credit)
2. [Extracting credit card expiration dates:](#extract-expiry-date)
3. [Matching CVV (Card Verification Value) codes:](#extract-cvv)


### Whitespace
- Regex:
```
\s+
```


### Phone Numbers

- 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
-

- 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)


### Email Addresses

- Validating email addresses:
- Regex pattern:
```
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
```
- Example formats:
- [email protected]
- [email protected]

- Extracting domain names from email addresses:
- Regex pattern:
```
@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
```
- Example formats:
- [email protected] (extracts example.com)
- [email protected] (extracts gmail.com)


### URLs

- Validating URLs:
- Regex pattern:
```
https?:\/\/[\w.-]+\.[\w.-]+[^\s]*
```
- Example formats:
- https://www.example.com
- http://ftp.example.com/file.txt


- Extracting different components of a URL(https://www.example.com/path/file.html?param1=value1&param2=value2):

- Extracting protocol:
- Regex pattern:
```
^(https?):\/\/
```
- Example format:
- https://
- http://

- Extracting domain:
- Regex pattern:
```
(https?):\/\/([a-zA-Z0-9.-]+)
```
- Example format:
- www.example.com
- www.google.com

- Extracting path:
- Regex pattern:
```
(https?):\/\/[a-zA-Z0-9.-]+(\/[^?\s]*)?
```
- Example format:
- /path/file.html

- Extracting query parameters:
- Regex pattern:
```
(https?):\/\/[a-zA-Z0-9.-]+(\/[^?\s]*)?(\?[^#\s]*)?$
```
- Example format:
- ?param1=value1&param2=value2
- Extracted Groups:
- https
- /path/file.html
- ?param1=value1&param2=value2


### Data Extraction

- Extracting specific patterns from unstructured text:

- To extract dates:
```
(\d{1,2})\/(\d{1,2})\/(\d{4})
```
- Example:
- Extract "12/31/2023" from a text.

- To extract times:
```
([01]\d|2[0-3]):([0-5]\d)
```
- Example:
- Extract "18:45" from a text.

- To extract addresses:
```
\d+\s[A-Za-z]+\s[A-Za-z]+,\s[A-Za-z]+\s\d+
```
- Example:
- Extract "123 Main St, New York 10001" from a text.

- Extracting values from structured data formats:

- To extract values from XML:
```
<(.*?)>([^<]+)<\/\1>
```
- Example:
- Extract values between XML tags, such as
```
# data

John Doe
25
[email protected]

# Expected Results
name John Doe
age 25
email [email protected]
```


### Credit Card

- Validating credit card numbers:
- Regex Pattern:
```
^(?:\d{4}[ -]?){3}\d{4}$
```
- Example Credit Card Numbers:
- 4111 1111 1111 1111
- 5555-5555-5555-4444
- 3782822463100058

- Extracting credit card expiration dates:
- Regex Pattern:
```
(?:0[1-9]|1[0-2])\/20[2-9][0-9]
```
- Example Expiration Dates:
- 12/2023
- 05/2025
- 09/2030

- Matching CVV (Card Verification Value) codes:
- Regex Pattern:
```
^\d{3,4}$
```
- Example CVV Codes:
- 123
- 7890
- 4321