[32984] in Perl-Users-Digest
Perl-Users Digest, Issue: 4260 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 7 05:17:17 2014
Date: Thu, 7 Aug 2014 02:17:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 7 Aug 2014 Volume: 11 Number: 4260
Today's topics:
Assert word boundary except for one character jomarbueyes@hotmail.com
Re: Assert word boundary except for one character <jimsgibson@gmail.com>
Re: Assert word boundary except for one character <derykus@gmail.com>
Re: Assert word boundary except for one character <gravitalsun@hotmail.foo>
Re: Assert word boundary except for one character <jomarbueyes@hotmail.com>
Re: Assert word boundary except for one character jomarbueyes@hotmail.com
Re: Assert word boundary except for one character jomarbueyes@hotmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 5 Aug 2014 14:19:53 -0700 (PDT)
From: jomarbueyes@hotmail.com
Subject: Assert word boundary except for one character
Message-Id: <45bb2ad0-19e7-4db1-88a9-15e9ecd54945@googlegroups.com>
Hi,
I need to modify some old Matlab code as follows:
this.OldName into this.newName
However, in
this.OldName.IsMessy
OldVariable should not be changed. The negative lookahead
s/\.OldName(?!\.)/.newName/
does work as long as there is not something like
this.OldNamePlusOtherStuff
I tried placing a word boundary \b assertion before the lookahead or after it. Neither approach matched this.OldName or this.Oldname.IsMessy.
Short of spelling out the characters that \b implies except for the dot, is there a way to exclude one (or more) character(s) from matching the \b assertion?
Thank you in advance for any guidance,
Jomar
------------------------------
Date: Tue, 05 Aug 2014 15:37:42 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Assert word boundary except for one character
Message-Id: <050820141537422033%jimsgibson@gmail.com>
In article <45bb2ad0-19e7-4db1-88a9-15e9ecd54945@googlegroups.com>,
<jomarbueyes@hotmail.com> wrote:
> Hi,
>
> I need to modify some old Matlab code as follows:
>
> this.OldName into this.newName
>
> However, in
>
> this.OldName.IsMessy
>
> OldVariable should not be changed. The negative lookahead
>
> s/\.OldName(?!\.)/.newName/
>
> does work as long as there is not something like
>
> this.OldNamePlusOtherStuff
>
> I tried placing a word boundary \b assertion before the lookahead or after
> it. Neither approach matched this.OldName or this.Oldname.IsMessy.
>
> Short of spelling out the characters that \b implies except for the dot, is
> there a way to exclude one (or more) character(s) from matching the \b
> assertion?
Sounds like you want to change 'OldName' to 'NewName' if it is followed
by:
1. A period
2. Whitespace
3. The end of the string
So try using positive lookahead:
s/\.OldName(?=[.\s]|$)/.NewName/
--
Jim Gibson
------------------------------
Date: Tue, 05 Aug 2014 22:41:17 -0700
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: Assert word boundary except for one character
Message-Id: <lrsf6h$v30$1@speranza.aioe.org>
On 8/5/2014 2:19 PM, jomarbueyes@hotmail.com wrote:
> Hi,
>
> I need to modify some old Matlab code as follows:
>
> this.OldName into this.newName
>
> However, in
>
> this.OldName.IsMessy
>
> OldVariable should not be changed. The negative lookahead
>
> s/\.OldName(?!\.)/.newName/
>
> does work as long as there is not something like
>
> this.OldNamePlusOtherStuff
>
I'm presuming then you don't want substitution in the case of
this.OldNamePlusOtherStuff.
> I tried placing a word boundary \b assertion before the lookahead
or after it. Neither approach matched this.OldName or this.Oldname.IsMessy.
>
> Short of spelling out the characters that \b implies except for the
dot, is there a way to exclude one (or more) character(s) from matching
the \b assertion?
Not particularly efficient.. In fact there are definitely better ways
but you could use the Randal Schwartz trick of chaining two zero-length
assertions:
s/\.OldName(?!\.)(?=\b)/.Newname/ # on \b boundary but exclude dot
Or, maybe just:
s/\.OldName(?![.\w])/.Newname/
See: perldoc perlre
--
Charles DeRykus
------------------------------
Date: Wed, 06 Aug 2014 13:22:28 +0300
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Assert word boundary except for one character
Message-Id: <lrsvk2$1jkb$1@news.ntua.gr>
#my $var = 'this.OldName.IsMessy2';
#my $var = 'this.OldName.IsMessy';
my $var = 'this.OldName';
if ( ( $var !~/\.IsMessy$/ ) && ( $var =~/(\w+).OldName(.*)/ ) )
{
$var = "$1.newName$2"
}
print $var;
------------------------------
Date: Wed, 6 Aug 2014 08:43:58 -0700 (PDT)
From: jomarbueyes at hot mail period com <jomarbueyes@hotmail.com>
Subject: Re: Assert word boundary except for one character
Message-Id: <65a25a20-b66c-40d3-bb05-ae0d930c1ba5@googlegroups.com>
On Wednesday, August 6, 2014 1:41:17 AM UTC-4, C.DeRykus wrote:
> On 8/5/2014 2:19 PM, jomarbueyes at hot mail period com wrote:
>
> > Hi,
>
> >
>
> > I need to modify some old Matlab code as follows:
>
> >
>
> > this.OldName into this.newName
>
> >
>
> > However, in
>
> >
>
> > this.OldName.IsMessy
>
> >
>
> > OldVariable should not be changed. The negative lookahead
>
> >
>
> > s/\.OldName(?!\.)/.newName/
>
> >
>
> > does work as long as there is not something like
>
> >
>
> > this.OldNamePlusOtherStuff
>
> >
>
>
>
>
>
> I'm presuming then you don't want substitution in the case of
>
> this.OldNamePlusOtherStuff.
>
>
>
>
>
> > I tried placing a word boundary \b assertion before the lookahead
>
> or after it. Neither approach matched this.OldName or this.Oldname.IsMessy.
>
> >
>
> > Short of spelling out the characters that \b implies except for the
>
> dot, is there a way to exclude one (or more) character(s) from matching
>
> the \b assertion?
>
>
>
> Not particularly efficient.. In fact there are definitely better ways
>
> but you could use the Randal Schwartz trick of chaining two zero-length
>
> assertions:
>
>
>
> s/\.OldName(?!\.)(?=\b)/.Newname/ # on \b boundary but exclude dot
>
>
>
> Or, maybe just:
>
>
>
> s/\.OldName(?![.\w])/.Newname/
>
>
>
> See: perldoc perlre
>
>
>
> --
>
> Charles DeRykus
Hi Charles,
Thank you very much for the suggestion. It does exactly what I need.
Thanks again,
Jomar
------------------------------
Date: Wed, 6 Aug 2014 08:52:11 -0700 (PDT)
From: jomarbueyes@hotmail.com
Subject: Re: Assert word boundary except for one character
Message-Id: <b75fe7f3-6c72-4243-8e3d-57fdb2ffa1e6@googlegroups.com>
On Tuesday, August 5, 2014 6:37:42 PM UTC-4, Jim Gibson wrote:
> In article <45bb2ad0-19e7-4db1-88a9-15e9ecd54945@googlegroups.com>,
>
> <jomarREMOVEbueyes at hotDELETEmail period com> wrote:
>
>
>
> > Hi,
>
> >
>
> > I need to modify some old Matlab code as follows:
>
> >
>
> > this.OldName into this.newName
>
> >
>
> > However, in
>
> >
>
> > this.OldName.IsMessy
>
> >
>
> > OldVariable should not be changed. The negative lookahead
>
> >
>
> > s/\.OldName(?!\.)/.newName/
>
> >
>
> > does work as long as there is not something like
>
> >
>
> > this.OldNamePlusOtherStuff
>
> >
>
> > I tried placing a word boundary \b assertion before the lookahead or after
>
> > it. Neither approach matched this.OldName or this.Oldname.IsMessy.
>
> >
>
> > Short of spelling out the characters that \b implies except for the dot, is
>
> > there a way to exclude one (or more) character(s) from matching the \b
>
> > assertion?
>
>
>
> Sounds like you want to change 'OldName' to 'NewName' if it is followed
>
> by:
>
> 1. A period
>
> 2. Whitespace
>
> 3. The end of the string
>
>
>
> So try using positive lookahead:
>
>
>
> s/\.OldName(?=[.\s]|$)/.NewName/
>
>
>
> --
>
> Jim Gibson
Hi Jim,
Thanks for your suggestion. However, I'm trying to change the name if it is followed by a word boundary that is not a period. I need to change the name if it is followed by :;,+=-!@#$ etc. (any word boundary, except a period).
Thanks again,
Jomar
Thank you
------------------------------
Date: Wed, 6 Aug 2014 08:56:24 -0700 (PDT)
From: jomarbueyes@hotmail.com
Subject: Re: Assert word boundary except for one character
Message-Id: <c490c9f2-080e-4713-897c-52b5b887ea2b@googlegroups.com>
On Wednesday, August 6, 2014 6:22:28 AM UTC-4, George Mpouras wrote:
> #my $var =3D 'this.OldName.IsMessy2';
>=20
> #my $var =3D 'this.OldName.IsMessy';
>=20
> my $var =3D 'this.OldName';
>=20
>=20
>=20
> if ( ( $var !~/\.IsMessy$/ ) && ( $var =3D~/(\w+).OldName(.*)/ ) )
>=20
> {
>=20
> $var =3D "$1.newName$2"
>=20
> }
>=20
>=20
>=20
> print $var;
Hi George,
Thank you for your suggestion. However, the "IsMessy" is just a place holde=
r for the example. If the name if followed by a period it always if followe=
d by some variable name. In that case, I need to keep the old variable name=
, regardless of the name that follows the period.=20
Thank you,
Jomar
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4260
***************************************