Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

regular expression

Posted on 2011-03-10
6
Medium Priority
?
419 Views
Last Modified: 2012-06-27
I have a bunch of urls like
http://www.travelpod.com/travel-blog-entries/bassalleckj/japan_se_asia07/1191895200/tpod.htm
and I want to reduce them to end at the .com/
I don't want all the extra subdirectory information and page information like
travel-blog-entries/bassalleckj/japan_se_asia07/1191895200/tpod.htm
to be there. So in the above example I just want
http://www.travelpod.com/

Can someone give me the regular expression for this? I am using notepad++ regular expression engine.

Thanks!
0
Comment
Question by:onyourmark
6 Comments
 
LVL 1

Accepted Solution

by:
notjames earned 668 total points
ID: 35105414
]$ perl -we '
use strict;

my $url = "http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q__26879493.html";

$url =~ s/(?:^(http.*\.com)).*$/$1/;

print $url,"\n";

'


Where

 $url =~ s/(?:^(http.*\.com)).*$/$1/;

 is the regex you're looking for.
0
 
LVL 3

Assisted Solution

by:ccwill88
ccwill88 earned 668 total points
ID: 35105598
The regular expression to get first part of url:

http://[A-Z0-9.]+/

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 58

Assisted Solution

by:amit_g
amit_g earned 664 total points
ID: 35106214
Find what:

(http://[^/]+)/.*

Open in new window


Replace with:

\1

Open in new window

0
 

Author Comment

by:onyourmark
ID: 35106330
This seems to find the entire string not just the ending

(http://[^/]+)/.*
0
 

Author Comment

by:onyourmark
ID: 35106335
Sorry, you are right. It works! Thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question