Page 1 of 1

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

Posted: Wed Feb 26, 2014 1:29 pm
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 ?

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

Posted: Tue Mar 04, 2014 9:28 am
by DataMystic Support
You need to use:

Code: Select all

([a-z])([A-Z])
otherwise the letters are not captured.

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

Posted: Tue Mar 04, 2014 9:57 pm
by simoninsing
Ahhh... Perfect. Many thanks.