Language: EN

regex-ejemplos-practicos

Regular Expression Examples

Basics

Detect uppercase words

Searches for words composed solely of uppercase letters.

Matches: "HELLO", "WORLD"

Does not match: "hello", "World"

Detect decimal numbers

Searches for integers or decimal numbers with or without a sign.

Matches: "3.14", "-100", "+0.5"

Does not match: "abc", "123."

Detect dates in format

Detects dates with separators / or -

Matches: "23/09/2023", "15-01-2022"

Does not match: "2022-09-23"

Networking

Detect URLs

Searches for HTTP/HTTPS protocols followed by a domain.

Matches: "http://www.example.com", "https://sub.domain.com/path"

Does not match: "www.example.com", "http//example"

Validate an IPv4 address

Finds addresses with four numeric blocks between 0 and 255.

Matches: "192.168.0.1", "255.255.255.0"

Does not match: "999.999.999.999", "123.456.789.0"

Validate an IPv6 address

Searches for addresses with 8 groups of 4 hexadecimal characters.

Matches: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"

Does not match: "1234:5678:90ab", "2001:::7334"

Files

Detect file names with specific extensions:

Searches for file names with extensions like .pdf, .jpg, etc.

Matches: "document.pdf", "image.jpg"

Does not match: "documenttxt", "image.docx"

Form validations

Detect usernames

Allows usernames between 3 and 16 characters that include letters, numbers, and underscores.

Matches: "Luis", "Pablo_92"

Does not match: "ac", "elcastigadordelasregularexpressions"

Detect secure passwords

Searches for passwords with at least 8 characters, including uppercase, lowercase, numbers, and symbols.

Matches: "Password1!", "A1b2C3$"

Does not match: "password", "12345678"

Detect email addresses

Identifies a username followed by @, a domain, and an extension.

Matches: "test@example.com", "user.name123@domain.co"

Does not match: "test@domain", "user@@domain.com"

Detect phone numbers

Searches for an optional country prefix followed by a phone number with optional spaces or dashes.

Matches: "+1-800-555-1234", "0044 20 7946 0958"

Does not match: "123456", "phone: +44 20"

Detect a credit card

Matches: "4111111111111111", "5500000000000004"

Does not match: "1234567890123456", "6011000000000004"

Markdown

Finds links where the text is between brackets and the URL is between parentheses.

Matches: "[LuisLlamas](https://luisllamas.es)"

Does not match: "[LuisLlamas.es](luisllamas.es)", "(https://luisllamas.es)"

Capture images in Markdown format

Searches for the pattern of an image with description and image URL.

Matches: "![Alt text](https://www.luisllamas.es/img/regex-icon.svg)"