CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
How to store (\w)



Oct 6, 2000, 6:11 PM

Post #1 of 4 (7875 views)
How to store (\w) Can't Post

is there any way to get the value of (\w) in this code the same way I can get (.*)

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if ($f[3] =~ m!(.*?)\.(.*?)/(\w)!){
}else{push(@good, $_);}

I tried using $3 but that's not what the \w is. \w should be like, index.html, default.asp, or something like that.



My Cat Attacks Me. We Call her Diablo Around here, I'm afraid to close my eyes at night.


Oct 6, 2000, 11:14 PM

Post #2 of 4 (7875 views)
Re: How to store (\w) [In reply to] Can't Post

\w will match a single character. Since (I assume) you're trying to match the filename at the end of the path, you might need to use ([^/]+)$ instead of (\w+)$

[This message has been edited by dws (edited 10-07-2000).]


Oct 7, 2000, 12:07 AM

Post #3 of 4 (7875 views)
Re: How to store (\w) [In reply to] Can't Post

Sorry, I miss explained that.

I should have said I am trying to use this code for matching urls. I'm trying to Identify the base domain urls from the other kinds.

I have been successfull so far.

Thanks For The Great Regex Though, Don't think for a minuet I'm not going to use that!

This is my first week that I'm really going to Dive into regex, I think it's very important for me to learn, and I'm reading as much as I can about it.

I think that this will work, correct me if I'm wrong,

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if($f[3] =~ m!(.*?)\.(.*?)/(.*{1}?)/!){
if ($3 eq "index.html" &#0124; &#0124; $3 eq "index.htm" &#0124; &#0124; $3 eq "main.htm" &#0124; &#0124; $3 eq "main.html" &#0124; &#0124; $3 eq "default.asp"){
push(@good, $_);
push(@good, $_);

That way,

Are pushed into @good

and stuff like

Aren't pushed into @good

Do you think I can have my Regex Diploma Now or Do I still Have A Long Way To Go, Smile


I'm Studying Regular Expressions and My Cat Is Still Shedding My Blood From Time to Time.


Oct 7, 2000, 8:45 AM

Post #4 of 4 (7875 views)
Re: How to store (\w) [In reply to] Can't Post

Needs a bit of work. Because you're not anchoring the regex, you'll get false hits for URLs like

The second possible problem is that hard-coding "index.htm" et al. isn't sufficient unless you control the web server configuration, since the list of defaults is configured on the web server side. Consider a server that likes index.php as a default.

The third problem is that your code pushes everything into @good. Oops.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives