What you need is Regexp::List
(http://search.cpan.org/dist/Regexp-Optimizer/lib/Regexp/List.pm). It
will take a list of strings and produce an optimal regex to find those
strings. You can then use a hash in the replacement to map to the
right key. For example, the list Chas Owens, John Smith, Jo
On 3/3/06, Ryan Gies <[EMAIL PROTECTED]> wrote:
>
> Ash Varma wrote:
> >
> > Any hint on the J Smith and J Smith Thomas ??
> >
>
> Hmm, good point. I'm sure there are several methods, but the first
> which comes to mind is to do two replacements...
>
> a. sort you list by the length(), processing
Ash Varma wrote:
Any hint on the J Smith and J Smith Thomas ??
Hmm, good point. I'm sure there are several methods, but the first
which comes to mind is to do two replacements...
a. sort you list by the length(), processing longer names first
b. 1st replacement replaces the all names with
On 3/3/06, Ryan Gies <[EMAIL PROTECTED]> wrote:
>
> > for ($i=0;$i<=$#id;$i++) {
> > $randomtext =~ s/$name[$i]/$name[$i] $id[$i]/g
> > }
>
> Putting the word-break identifiers around your search text will prevent
> "J Smithers" from getting replaced when the $i for "J Smith" comes around.
>
>
for ($i=0;$i<=$#id;$i++) {
$randomtext =~ s/$name[$i]/$name[$i] $id[$i]/g
}
Putting the word-break identifiers around your search text will prevent
"J Smithers" from getting replaced when the $i for "J Smith" comes around.
$randomtext =~ s/\b$name[$i]\b/$name[$i] $id[$i]/g
--
To unsu
On 3/3/06, Wagner, David --- Senior Programmer Analyst --- WGO <
[EMAIL PROTECTED]> wrote:
>
> Ash Varma wrote:
> > Hi..
> >
> > I have 2 files of data..
> >
> > File 1 = id,name
> >
> > eg:
> >
> > 0001, J Smith
> > 0002, J Smithers
> > 0003 J Smith Thomas
> >
> >
> > File 2 = general text, with n
Ash Varma wrote:
> Hi..
>
> I have 2 files of data..
>
> File 1 = id,name
>
> eg:
>
> 0001, J Smith
> 0002, J Smithers
> 0003 J Smith Thomas
>
>
> File 2 = general text, with names recorded at different locations..
>
> eg.
>
> This is random text for with J Smith, J Smithers and J Smith Tho
Hi..
I have 2 files of data..
File 1 = id,name
eg:
0001, J Smith
0002, J Smithers
0003 J Smith Thomas
File 2 = general text, with names recorded at different locations..
eg.
This is random text for with J Smith, J Smithers and J Smith Thomas
I am trying to replace all J Smiths with J Smith