TP: Perl expression problem with $0, $1, $2

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

simoninsing
Posts: 18
Joined: Fri Jun 05, 2009 11:11 pm

TP: Perl expression problem with $0, $1, $2

Postby simoninsing » Wed Feb 26, 2014 1:29 pm

Having some problems getting $1, $2 to work for me in a replace command. Need to fix up a long list of names where the middle name is jammed up against the surname, e.g. "Lee HarveyOswald". Seems that the cleanest way to do this would be to run a Replace command to find all instances of a lower case letter sitting next to (without a space in between) an upper case letter, and getting the script to add a space.

When I use the perl pattern option in Replace, and put
[a-z][A-Z]
as the input, and
$1 $2
as the output, I get an error message saying "$1 is not a valid subexpression identifier ..."

And yet if I only have one input variable (say [a-z]) and put $0 as the output, it works fine. Seems that it's only the fact that there are two or more input variables that is causing the problem. I tried the Old Egrep pattern option also and hit the same problem.

What am I doing wrong ?

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

Re: TP: Perl expression problem with $0, $1, $2

Postby DataMystic Support » Tue Mar 04, 2014 9:28 am

You need to use:

Code: Select all

([a-z])([A-Z])

otherwise the letters are not captured.
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

simoninsing
Posts: 18
Joined: Fri Jun 05, 2009 11:11 pm

Re: TP: Perl expression problem with $0, $1, $2

Postby simoninsing » Tue Mar 04, 2014 9:57 pm

Ahhh... Perfect. Many thanks.


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Yahoo [Bot] and 7 guests