Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

regular expression

Posted on 2011-03-10
6
Medium Priority
?
417 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
[X]
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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

715 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