Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

regular expression

Posted on 2011-03-10
6
411 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
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.
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…

809 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