A simply regex question

F

Franzl Wisseworst

How can I figure if my DOCUMENT_URI contains a substring, eg.:

if ($ENV{"DOCUMENT_URI"} contains string "mein.totenkopf.de"){
do something...;
}

And is there a way to ignore case, so the substring could be
"mein.totenkopf.de" or "MEIN.TOTENKOPF.DE" for example?

The purpose is to identify if the only the base domain or sub-domain is
being accessed. The reason I'd like to utilise DOCUMENT_URI rather than
REMOTE_HOST or some other domain specific string is because it should work
on a local machine too, where all content is mirorred, but where
REMOTE_HOST is always localhost. This should work in both environments
because the full domain substring exist as a directory name in both cases.

Many thanks for any tips.
 
P

Paul Lalli

Franzl said:
How can I figure if my DOCUMENT_URI contains a substring, eg.:

if ($ENV{"DOCUMENT_URI"} contains string "mein.totenkopf.de"){
do something...;
}

And is there a way to ignore case, so the substring could be
"mein.totenkopf.de" or "MEIN.TOTENKOPF.DE" for example?

This is not meant to sound rude, but if you have to ask this question,
then you haven't read even a decent tutorial on Perl yet. You should
do so. Open a command line, and type "perldoc perlintro".

Pay attention to the part on "pattern matching" and/or "regular
expressions".

Paul Lalli
 
D

Dr.Ruud

Franzl Wisseworst schreef:

Your subject has no quality. Please come up with something like
"How to detect substring?"
How can I figure if my DOCUMENT_URI contains a substring

perldoc -f index

And is there a way to ignore case

perldoc -f lc
 
J

Jürgen Exner

Franzl Wisseworst wrote:
[Subject: A simply regex question]

Your task can better be solved without using a RE.
How can I figure if my DOCUMENT_URI contains a substring, eg.:

perldoc -f index
And is there a way to ignore case, so the substring could be
"mein.totenkopf.de" or "MEIN.TOTENKOPF.DE" for example?

You normalize both strings before searching, e.g. make both all lower-case,
see
perldoc -f lc

jue
 
F

Franzl Wisseworst

Jürgen Exner said:
Your task can better be solved without using a RE.

I opted for something simple like:
$domain_string =~ /mein.totenkopf.de/
You normalize both strings before searching, e.g. make both all
lower-case, see
perldoc -f lc

How obvious! Thank you.
 
J

Jürgen Exner

Franzl said:
I opted for something simple like:
$domain_string =~ /mein.totenkopf.de/

You realize that this RE matches e.g. 'mein#totenkopfXde', too, do you?
Beside, as pointed out earlier, there is no need to crank the big RE engine
for a simple textual comparison as you are looking for.
How obvious! Thank you.

Which of course is not even needed. If you are cranking the big RE engine
already, then you could just as well take advantage of its power and search
case-insensitive: perldoc perlre.

jue
 
F

Franzl Wisseworst

[..]

If I only knew how to...
You realize that this RE matches e.g. 'mein#totenkopfXde', too, do you?

No I did not.

[..]
search case-insensitive: perldoc perlre.

Will munch through this bit of documentation too.

Thank you for the information.
 

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,777
Messages
2,569,604
Members
45,233
Latest member
AlyssaCrai

Latest Threads

Top