|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
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 |
|
#8
|
|||
|
|||
|
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 |
|
#9
|
|||
|
|||
|
Got it
if($httpref =~ m/^((?:http|ftp):\/\/.*?\/)/i){
print $1; } been tested... it should work... |
|
#10
|
|||
|
|||
|
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 |
|
#11
|
|||
|
|||
|
Hmm
Quote:
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... |
|
#12
|
|||
|
|||
|
Do ya one better
.Code:
$fullurl =~ m%^([^:]+://[^/]+)/.*$%i; $baseurl = $1; |
|
#13
|
|||
|
|||
|
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 ![]() |
|
#14
|
|||
|
|||
|
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
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Regex question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|