Search & Replace anomaly

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

NoDFs

Search & Replace anomaly

Postby NoDFs » Wed Jul 23, 2003 7:49 am

I am trying to extract a relatively simple pattern out of each line in a file but come up with wierd results. I think I got lucky and made an expression that works but do not understand why it does not work in a simpler method. Both methods are below.

SAMPLE TEXT:
T01c.001 F001 S40
T02 C.002F002 S40
T03C.003F003 S40
T04 C.004 F004 S40
T05F005c.005 S40
T06 F006 c.006 S40

Perl pattern Search:
t\d+\D*.*c.(\d\d\d\d|\d\d\d|\d\d|\d)\D+.*.$
-or-
t\d+\D*.*c.(\d{1,4})\D+.*.$

Replaces with:
C.$1

Output (desired):
C.001
C.002
C.003
C.004
C.005
C.006


I dont understand why the S&R pattern below does not work.

Perl pattern Search:
t\d+\D*.*c.(\d+).*

Replaces with ("-" used to see and troubleshoot capture):
C.-$1-

Output (undesired):
C.-0-01 F001 S40
C.-0-02F002 S40
C.-0-03F003 S40
C.-0-04 F004 S40
C.-0-05 S40
C.-0-06 S40


Please explain why the capture is not getting the whole set of digits and why the end of the line is not dropping off.

Thanks so much! :)

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

Re: Search & Replace anomaly

Postby DataMystic Support » Wed Jul 23, 2003 4:19 pm

Just use the pattern

c.(\d{1,4}?)

With the 'Extract' option on, and a replace pattern of

C.$1\r\n
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 “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: Bing [Bot] and 9 guests