Solved

regular expression

Posted on 2011-03-10
6
409 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl string replace for refred url 9 59
Help with powershell and regex 5 46
Perl string filter 5 72
Greater than or equal to 2005? 3 35
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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

911 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

18 Experts available now in Live!

Get 1:1 Help Now