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

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
simoninsing
Posts: 20
Joined: Fri Jun 05, 2009 11:11 pm

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

Post by simoninsing »

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: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

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

Post by DataMystic Support »

You need to use:

Code: Select all

([a-z])([A-Z])
otherwise the letters are not captured.
simoninsing
Posts: 20
Joined: Fri Jun 05, 2009 11:11 pm

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

Post by simoninsing »

Ahhh... Perfect. Many thanks.
Post Reply