Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 24th, 2001, 05:06 PM
startrader startrader is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 startrader User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Regex question

Hi,
how do i write a regex which will convert/replace the following examples(below) to URL ? I want to remove the text /bla/index.html and /bla/bla/index.html

examples...
URL
URL
etc...

Sincerely
Adam

Reply With Quote
  #2  
Old June 25th, 2001, 04:21 AM
thobbes867 thobbes867 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Northern Ohio
Posts: 75 thobbes867 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
you could use a single frame webpage. I don't know if that is the best way to do it, but I am sure that it is the easiest.

Reply With Quote
  #3  
Old June 25th, 2001, 06:35 AM
startrader startrader is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 startrader User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yeah , but in this case i need to cath the referer-url and then do i kind of substring/reg expr to remove everything else but main domain url as i wrote earlier... i hate frames,so that wouldnt help me :-}
thanks anyway
adam

Reply With Quote
  #4  
Old June 25th, 2001, 09:07 AM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I think I get what you need

Try something like this

if($yourvar =~ m/^((?:http)|(?:ftp):\/\/.*?\//i){
#$1 now = the http/ftp address of the refering page
}else{
#There was no domain that this script could capture...
}

Might need a few modifications... but I think it'll work... haven't tested it though

Reply With Quote
  #5  
Old June 25th, 2001, 10:43 AM
mullaney mullaney is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 0 mullaney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try a substitute.

$URL =~ s|([^/]{2,3}?)(/.*)*|$1|g;

This will look for the string from the beginning of the line leading to the 2nd or 3rd occurance of the slash (/) and disregard the rest.

Bob

Reply With Quote
  #6  
Old June 25th, 2001, 02:39 PM
startrader startrader is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 startrader User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi :-}

i tested with following result ...

if($ref =~ m/^(?:http)|(?:ftp):\/\/.*\//ig){
print " $& ";
}else{
}

it only catch http from the refstring URL

and..

$ref =~ s|([^/]{2,3}?)(/.*)*|$1|g;
didnt work at all? If i print out $ref , it will print the whole url.

Regards
Adam

Reply With Quote
  #7  
Old June 25th, 2001, 04:17 PM
mullaney mullaney is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 0 mullaney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Another approach

If you can guarantee the format of the url, you can try this.

--
@URL = split (/\//, $ref);
print "$URL[0]\/\/$URL[2]\n";
--

$ref must contain two slashes before the domain name and one after for this to work. If you can ensure the format, this may be the simpler way to go. BTW, sorry about the regex prob...mine works

Good Luck,
Bob

Reply With Quote
  #8  
Old June 25th, 2001, 04:44 PM
startrader startrader is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 startrader User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks Bob,
it seems to work fine, but i cant ensure the format, because the script has to be more flexible. The script is a kind of a counter which has to count every page from a specific domain as one, so it might happen that a subdomain is a referel, and then im stuck

Regards,
Adam

Reply With Quote
  #9  
Old June 25th, 2001, 09:00 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Got it

if($httpref =~ m/^((?:http|ftp):\/\/.*?\/)/i){
print $1;
}


been tested... it should work...

Reply With Quote
  #10  
Old June 26th, 2001, 02:37 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
Startrader,

http://www.domain.com/bla/index.html
http://www.domain.com/bla/bla/index.html

Just to make sure I understand, all you want is the base URL.

If that's the case you could do something like:

Code:
$fullurl = "http://www.domain.com/bla/index.html

$fullurl =~ m%(^http://[^/]+)/.*$%;
$baseurl = $1;


You may need to tweak it a little bit, but that general idea should do the trick.
__________________
- dsb -
Perl Guy

Reply With Quote
  #11  
Old June 26th, 2001, 02:44 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hmm

Quote:
Originally posted by dsb
Startrader,

Just to make sure I understand, all you want is the base URL.

If that's the case you could do something like:

Code:
$fullurl = "http://www.domain.com/bla/index.html

$fullurl =~ m%(^http://[^/]+)/.*$%;
$baseurl = $1;


You may need to tweak it a little bit, but that general idea should do the trick.


He said above, that he isn't sure where the link may be coming from... there are things out there becides http... ie... FTP...
----------------------------

What I wrote above will work (as I said, tested), you can add an else at the end to do something if it CANT find the domain...

Reply With Quote
  #12  
Old June 26th, 2001, 03:27 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
Do ya one better .

Code:
$fullurl =~ m%^([^:]+://[^/]+)/.*$%i;
$baseurl = $1;

Reply With Quote
  #13  
Old June 26th, 2001, 05:40 PM
startrader startrader is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 startrader User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks for your help everyone...

its no need for a ftp check ...what i need is a fast way to check a referel(http) which might be one of the domain names that i have in a textfile... soo lets say that three referel will be sent
from another domain , ex:
ref 1 URL
ref 2 URL
ref 3 URL

then i have to match the three referels to the name domainx.com (which i have in a textfile) and the sum should be 3 (0 in the beginning).

i know that i could write if($fullurl =~ /$domainname/) and then loop throught the textfile... but i prefer not to use regex expr to much, because i find it pretty slow, soo i want to use the following syntax if(incoming_domain_name eq $domainname_from_textfile){blabla}

cheers
Adam

Reply With Quote
  #14  
Old June 26th, 2001, 06:35 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Umm....

First, let me say one thing... Perl is BUILT on regexes... and because of that, it is very good at them... second, there is no means of simple $var == $var2 comparison to get the results you want WITHOUT regex... sorry

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Regex question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |