Regular Expression Help?

T

Trespasser

Hi,

I can appreciate what a wonderfully powerful tool regular expressions are,
but I am still learning and seem to need a little help.

I have an example of a regular expression for an Apache server mod_rewrite
module rewrite trigger condition.

^www.\.[^.]+\.domain\.com$

As far as I can gather this is supposed to match www.username.domain.com,
where 'username' could be any system user's username or other alphanumeric
character sequence.

Can anyone please tell me how I can modify this type of regular expression
as follows? I want the rule to match for sequences like username.domain.com
and otherusername.domain.com, but specifically not to match for
www.domain.com.

I would so appreciate it if somebody could please lend me some of their
valuable expertise to help solve my dilemma.

Regards,
Tressie.
 
T

Tim Greer

Trespasser said:
Hi,

I can appreciate what a wonderfully powerful tool regular expressions
are, but I am still learning and seem to need a little help.

I have an example of a regular expression for an Apache server
mod_rewrite module rewrite trigger condition.

^www.\.[^.]+\.domain\.com$

You probably don't want ^www.\., but ^www\. instead.
As far as I can gather this is supposed to match
www.username.domain.com, where 'username' could be any system user's
username or other alphanumeric character sequence.

Can anyone please tell me how I can modify this type of regular
expression as follows? I want the rule to match for sequences like
username.domain.com and otherusername.domain.com, but specifically not
to match for www.domain.com.

What about domain.com? Will you want to be matching
www.something.example.com, still as well?
 
T

Trespasser

Hi Tim,

Thanks very much for responding to my regular expression query.

^www\..[^.]+\.domain\.com$

Yes, this is the corrected form of the example expression. Sorry about the
mix up.
What about domain.com? Will you want to be matching
www.something.example.com, still as well?

I've just discovered that I can create DNS A records from URLs of the
www.something.example.com form. This form of match is interesting as well. I
think the example trigger expression is intended to accommodate this form,
but not the www.domain.com and username.domain.com forms as well.

Yes, triggering on username.domain.com and otherusername.domain.com, but not
on www.domain.com is the single focus my interest here. I can't figure how
to write a regular expression that triggers on the 3-tier URL, but not if
the first word is www.

Any suggestions, Tim?

Regards,
Tressie.

Tim Greer said:
Trespasser said:
Hi,

I can appreciate what a wonderfully powerful tool regular expressions
are, but I am still learning and seem to need a little help.

I have an example of a regular expression for an Apache server
mod_rewrite module rewrite trigger condition.

^www.\.[^.]+\.domain\.com$

You probably don't want ^www.\., but ^www\. instead.
As far as I can gather this is supposed to match
www.username.domain.com, where 'username' could be any system user's
username or other alphanumeric character sequence.

Can anyone please tell me how I can modify this type of regular
expression as follows? I want the rule to match for sequences like
username.domain.com and otherusername.domain.com, but specifically not
to match for www.domain.com.

What about domain.com? Will you want to be matching
www.something.example.com, still as well?
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
T

Tad J McClellan

Trespasser said:
Hi Tim,

Thanks very much for responding to my regular expression query.

^www\..[^.]+\.domain\.com$

Yes, this is the corrected form of the example expression.


That will match

www..user.domain.com

....

Yes, triggering on username.domain.com and otherusername.domain.com, but not
on www.domain.com is the single focus my interest here. I can't figure how
to write a regular expression that triggers on the 3-tier URL, but not if
the first word is www.

Any suggestions, Tim?


I am not Tim, yet I have a suggestion.

Use a negative lookahead assertion:

-----------------------------
#!/usr/bin/perl
use warnings;
use strict;

foreach my $domain ( qw/ www.domain.com www.something.domain.com
username.domain.com otherusername.domain.com
wwwfoobar.domain.com / ) {
print "$domain matched\n"
if $domain =~ /^(?!www\.)[^.]+\.domain\.com$/;
}
 
B

Ben Bacarisse

Trespasser said:
Thanks very much for responding to my regular expression query.

^www\..[^.]+\.domain\.com$

Yes, this is the corrected form of the example expression. Sorry about the
mix up.

Tim suggested /^www\.[^.]+\.domain\.com$/. You still have an extra
'.' in there.
I've just discovered that I can create DNS A records from URLs of the
www.something.example.com form. This form of match is interesting as well. I
think the example trigger expression is intended to accommodate this form,
but not the www.domain.com and username.domain.com forms as well.

Yes, triggering on username.domain.com and otherusername.domain.com, but not
on www.domain.com is the single focus my interest here. I can't figure how
to write a regular expression that triggers on the 3-tier URL, but not if
the first word is www.

Perl has a negative look-behind that can be used when the string you
must avoid is fixed length:

/(?<!www)\.domain\.com$/

but this may not be what you want. Note the ^ has gone. This meets
the narrow interpretation of your request but may not do what want
with names like www.other.domain.com (matches) and
other.www.domain.com (it does not match). I think that was the force
of Tim's clarifying question.
 
B

Bruce Cook

Trespasser said:
Hi,

I can appreciate what a wonderfully powerful tool regular expressions are,
but I am still learning and seem to need a little help.

I have an example of a regular expression for an Apache server mod_rewrite
module rewrite trigger condition.

^www.\.[^.]+\.domain\.com$

[...]

I'm not sure if you've found this already, but you can turn on logging for
mod_rewrite in apache. I have found it quite useful in the past.

Bruce
 

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
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top