Regexp not working

B

Ben Morrow

chatiman said:
I'm tryng to mach all url of a domain :
http://host1.domain.com/
http://host2.domain.com/
http://www.domain.com/

For that I'm using the following regexp:
/http:\/\/[^\.]+domain.com/

You are missing a dot after the first component of the name.

m#http://[^.]+.domain.com#

I don't know if you realise that . doesn't need escaping in a character
class; or if you care that this will match lots of invalid UR[LI]s (such
as http://%#>?&.domain.com/). You may wish to use Regexp::Common, which
will correctly match various bits of valid URIs.

Ben
 
T

Tassilo v. Parseval

Also sprach Ben Morrow:
chatiman said:
I'm tryng to mach all url of a domain :
http://host1.domain.com/
http://host2.domain.com/
http://www.domain.com/

For that I'm using the following regexp:
/http:\/\/[^\.]+domain.com/

You are missing a dot after the first component of the name.

m#http://[^.]+.domain.com#

I don't know if you realise that . doesn't need escaping in a character
class; or if you care that this will match lots of invalid UR[LI]s (such
as http://%#>?&.domain.com/). You may wish to use Regexp::Common, which
will correctly match various bits of valid URIs.

Not in character classes, but outside of them it does. :)

m#http://[^.]+\.domain\.com#

Tassilo
 
D

Dave Cardwell

chatiman said:
Hello,

I'm tryng to mach all url of a domain :
http://host1.domain.com/
http://host2.domain.com/
http://www.domain.com/

For that I'm using the following regexp:
/http:\/\/[^\.]+domain.com/

I can't understand why it is not working.

Anyone knows ?

m#http://[a-zA-Z0-9][a-zA-Z0-9-]*?.domain.com#

Will match only match valid bits (letters, numbers and -s, without a - as
the first character. That probably won't cover everything, you may want to
look at the RFCs.

Regards,
 
D

Dave Cardwell

Dave Cardwell said:
chatiman said:
Hello,

I'm tryng to mach all url of a domain :
http://host1.domain.com/
http://host2.domain.com/
http://www.domain.com/

For that I'm using the following regexp:
/http:\/\/[^\.]+domain.com/

I can't understand why it is not working.

Anyone knows ?

m#http://[a-zA-Z0-9][a-zA-Z0-9-]*?.domain.com#

Will match only match valid bits (letters, numbers and -s, without a - as
the first character. That probably won't cover everything, you may want to
look at the RFCs.

Nuts, forgot to escape the .s, try
m#http://[a-z0-9][a-z0-9-]*\.domain\.com#oi instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top