C
C
Chvanikoff2011-02-08 21:10:30
Regular Expressions
Chvanikoff, 2011-02-08 21:10:30

Need help with a regex - validating all sorts of addresses (URLs)?

Hello!
I have such a regular program, which until recently coped with its work with a bang:

~^

# scheme
[-a-z0-9+.]++://

# username:password (optional)
(?:
        [-a-z0-9$_.+!*\'(),;?&=%]++   # username
    (?::[-a-z0-9$_.+!*\'(),;?&=%]++)? # password (optional)
    @
)?

(?:
    # ip address
    \d{1,3}+(?:\.\d{1,3}+){3}+

    | # or

    # hostname (captured)
    (
            (?!-)[-a-z0-9]{1,63}+(?<!-)
        (?:\.(?!-)[-a-z0-9]{1,63}+(?<!-)){0,126}+
    )
)

# port (optional)
(?::\d{1,5}+)?

# path (optional)
(?:/.*)?

$~iDx

But, as many of you have probably heard, we have an amazing
domain.RF will also miss correctly written Russian-letter addresses.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2011-02-08
@Chvanikoff

translate to punycode and validate

A
Anatoly, 2011-02-10
@taliban

Off topic, of course =) But I'll add this question to my favorites, and I'll poke everyone's nose on how regular seasons should be designed :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question