Perl Regex Problem

A discussion of how to use EasyPatterns, EasyPattern Helper and using the EasyPattern library.

Moderator: DataMystic Support

allsystems
Posts: 2
Joined: Thu Oct 24, 2013 2:26 am

Perl Regex Problem

Postby allsystems » Sat Dec 28, 2013 4:45 am

Hi,

I have been struggling with this issue. I am using Text Pipe to trim a sample of URLs to the root domains. Basically I am wanting to delete everything after the "/" including the "/" sign. I have used this regex a million times before but cant get it to work. Here is the regex:

/.*

I am using the find and replace Perl style. It should change this:

domain1.com/sometext/
domain2.com/another-piece-of text/

to:

domain1.com
domain2.com

Where am I going wrong?

allsystems
Posts: 2
Joined: Thu Oct 24, 2013 2:26 am

Re: Perl Regex Problem

Postby allsystems » Sat Dec 28, 2013 11:05 am

For anyone interested this seems to work:

/.*$


Not sure why tho

User avatar
DataMystic Support
Site Admin
Posts: 2138
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Perl Regex Problem

Postby DataMystic Support » Tue Dec 31, 2013 10:39 pm

You assumed that .* would stop at the end of the line- it doesn't - it consumes the rest of the file, or a large chunk of it.

That's why
/.*$
works, although
/[^\r\n]*
is better and faster.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments


Return to “EasyPatterns Support”

Who is online

Users browsing this forum: No registered users and 1 guest