Solved

regular expression

Posted on 2011-03-10
6
407 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 167 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 167 total points
ID: 35105598
The regular expression to get first part of url:

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

Open in new window

0
 

Author Comment

by:onyourmark
ID: 35105949
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 58

Assisted Solution

by:amit_g
amit_g earned 166 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now