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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



perlkid
stranger

Oct 6, 2000, 6:11 PM

Post #1 of 4 (2121 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, $_);}
</pre><HR></BLOCKQUOTE>

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

Thanks,

Perlkid

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



dws
Deleted

Oct 6, 2000, 11:14 PM

Post #2 of 4 (2121 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).]


perlkid
stranger

Oct 7, 2000, 12:07 AM

Post #3 of 4 (2121 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, $_);
}
}else{
push(@good, $_);
}
</pre><HR></BLOCKQUOTE>

That way,
http://www.perlguru.com/index.html http://www.perlguru.com/ http://www.perl.com/index.htm

Are pushed into @good

and stuff like
http://www.perlguru.com/cgi-bin/forum/postings.cgi http://www.perlguru.com/Ultimate.cgi http://www.perlguru.com/forum/anotherpage.html

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

perlkid

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


dws
Deleted

Oct 7, 2000, 8:45 AM

Post #4 of 4 (2121 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
http://fake.domain/path.with.dots/index.html

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