Regular Expression help
am 02.03.2007 21:59:23 von amit hetawal
Hello all,
I have a string which comes from a database entry which looks like:
$temp = "XXXXX'YYYY'ZZZZ";
now i want to remove all the single qoutes from this string ( ' ) so
as to make it looks like:
"XXXXXYYYYZZZZ"
I am trying to write a simple regex for it but its not working for me.
$temp = ~s/^'$//g;
i know there is something wrong with the ( ' ) 's . But dont know what.
Please advice whats going wrong here, and whats the idea behind this.
Thanks
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular Expression help
am 02.03.2007 22:05:25 von Deane.Rothenmaier
This is a multipart message in MIME format.
--===============1526188374==
Content-Type: multipart/alternative;
boundary="=_alternative 0073DD5086257292_="
This is a multipart message in MIME format.
--=_alternative 0073DD5086257292_=
Content-Type: text/plain; charset="us-ascii"
>$temp = ~s/^'$//g;
Remove the '^' and '$' anchors. what your expression is expecting to work
on is a string that consists solely of a single-quote.
Try
$temp =~ s/'//g;
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
Babbage, if you put into the machine wrong figures, will the right answers
come out?' I am not able rightly to apprehend the kind of confusion of
ideas that could provoke such a question." -- Charles Babbage
--=_alternative 0073DD5086257292_=
Content-Type: text/html; charset="us-ascii"
>$temp = ~s/^'$//g;
Remove the '^' and '$' anchors. what your expression is expecting to work on is a string that consists solely of a single-quote.
Try
$temp =~ s/'//g;
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage
--=_alternative 0073DD5086257292_=--
--===============1526188374==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1526188374==--
Re: Regular Expression help
am 02.03.2007 22:09:44 von amit hetawal
hello,
I tried this also,
my actual string looks like:
$temp='196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedme mbraneproteinSequence
:196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedmembrane protein';
#$name = $1;
$temp = ~s/'//g;
print $temp;
its gives me: 4294967295 i dont know what this is...
On 3/2/07, Deane.Rothenmaier@walgreens.com
wrote:
>
> >$temp = ~s/^'$//g;
>
> Remove the '^' and '$' anchors. what your expression is expecting to work on
> is a string that consists solely of a single-quote.
>
> Try
>
> $temp =~ s/'//g;
>
>
> Deane Rothenmaier
> Systems Architect
> Walgreens Corp.
> 847-914-5150
>
> "On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
> Babbage, if you put into the machine wrong figures, will the right answers
> come out?' I am not able rightly to apprehend the kind of confusion of ideas
> that could provoke such a question." -- Charles Babbage
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular Expression help
am 02.03.2007 22:12:46 von Kevin Roland Viel
On Fri, 2 Mar 2007, amit hetawal wrote:
> Hello all,
>
> I have a string which comes from a database entry which looks like:
>
> $temp = "XXXXX'YYYY'ZZZZ";
> now i want to remove all the single qoutes from this string ( ' ) so
> as to make it looks like:
>
> "XXXXXYYYYZZZZ"
>
> I am trying to write a simple regex for it but its not working for me.
>
> $temp = ~s/^'$//g;
>
> i know there is something wrong with the ( ' ) 's . But dont know what.
>
>
> Please advice whats going wrong here, and whats the idea behind this.
You don't need the anchors (^,$). If I understand this correctly, then
the only line it would match is:
'
A single byte line, not including the /n.
HTH,
Kevin
Kevin Viel
PhD Candidate
Department of Epidemiology
Rollins School of Public Health
Emory University
Atlanta, GA 30322
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular Expression help
am 02.03.2007 22:17:25 von Andy_Bach
> I am trying to write a simple regex for it but its not working for me.
$temp = ~s/^'$//g;
Well, you're heart is in the right place but ... ;-> The 'anchors' here:
carret "^" meaning "beginning of string" and the "$" meaning "end of
string", are limiting your match to match a string w/ only a single quote
in it. You want to get any quote. You probably want to put the tilda "~"
back next to the '=' sign too, so:
$temp =~ s/'//g;
is how to remove all single quotes. Another route is 'tr' and the
"delete" flag:
$temp =~ tr/'//d;
does the same thing. I've heard 'tr' is more efficient, if that matters
(probably doesn't).
a
Andy Bach
Systems Mangler
Internet: andy_bach@wiwb.uscourts.gov
VOICE: (608) 261-5738 FAX 264-5932
"Procrastination is like putting lots and lots of commas in the sentence
of your life."
Ze Frank
http://lifehacker.com/software/procrastination/ze-frank-on-p rocrastination-235859.php
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Regular Expression help
am 02.03.2007 22:18:07 von JavierMoreno
hello,
I tried this also,
my actual string looks like:
$temp='196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedme mbraneprotei
nSequence
:196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedmembrane protein';
#$name = $1;
$temp = ~s/'//g;
print $temp;
its gives me: 4294967295 i dont know what this is...
>>>>>>>
I tried this and it worked I don't know why it initially gave me your
same result
$temp='196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedme mbraneprotei
nSequence
:196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedmembrane protein';
#$name = $1;
print "$temp\n\n";
$temp =~ s/\'//g;
print "$temp\n";
Regards,
Javier Moreno
----------------
Systems Engineer - Transmissions
"When you have eliminated all which is impossible, then whatever
remains, however improbable, must be the truth" - Sherlock Holmes
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular Expression help
am 02.03.2007 22:19:27 von Andy_Bach
$temp='196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedme mbraneproteinSequence
:196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedmembrane protein';
#$name = $1;
$temp = ~s/'//g;
print $temp;
its gives me: 4294967295 i dont know what this is...
the space is giving you an assigment (from the "=") to $temp of the binary
inverse (from the "~") of the number of match/substitutes for a single
quote (from the s///g).
a
Andy Bach
Systems Mangler
Internet: andy_bach@wiwb.uscourts.gov
VOICE: (608) 261-5738 FAX 264-5932
"Procrastination is like putting lots and lots of commas in the sentence
of your life."
Ze Frank
http://lifehacker.com/software/procrastination/ze-frank-on-p rocrastination-235859.php
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular Expression help
am 02.03.2007 22:20:15 von amit hetawal
Ahhhh....
Sorry about that i got it.. It was a wrong way i was using the
=~ s. thing..
My bad !!!!
On 3/2/07, Kevin Roland Viel wrote:
> On Fri, 2 Mar 2007, amit hetawal wrote:
>
> > Hello all,
> >
> > I have a string which comes from a database entry which looks like:
> >
> > $temp = "XXXXX'YYYY'ZZZZ";
> > now i want to remove all the single qoutes from this string ( ' ) so
> > as to make it looks like:
> >
> > "XXXXXYYYYZZZZ"
> >
> > I am trying to write a simple regex for it but its not working for me.
> >
> > $temp = ~s/^'$//g;
> >
> > i know there is something wrong with the ( ' ) 's . But dont know what.
> >
> >
> > Please advice whats going wrong here, and whats the idea behind this.
>
> You don't need the anchors (^,$). If I understand this correctly, then
> the only line it would match is:
>
> '
>
> A single byte line, not including the /n.
>
> HTH,
>
> Kevin
>
> Kevin Viel
> PhD Candidate
> Department of Epidemiology
> Rollins School of Public Health
> Emory University
> Atlanta, GA 30322
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Regular Expression help
am 02.03.2007 22:26:36 von Andy_Bach
$temp=3D'196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conserved membraneprotein=
Sequence
:196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedmembrane protein';
#$name =3D $1;
$temp =3D ~s/'//g;
print $temp;
> its gives me: 4294967295 i dont know what this is...
I misspoke, slightly:
$temp =3D ~s/'//g;
the s/// is working on the current $_ and then taking the binary negation =
(perldoc perlop):
Unary "~" performs bitwise negation, i.e., 1=E2s complement. For example, =
"0666 & ~027" is 0640. (See also "Integer
Arithmetic" and "Bitwise String Operators".) Note that the width =
of the result is platform-dependent: ~0 is 32 bits
wide on a 32-bit platform, but 64 bits wide on a 64-bit platform, =
so if you are expecting a certain bit width, remember
to use the & operator to mask off the excess bits.
and that - so '4294967295' is probably the binary negation of zero unless =
you happen to have something in $_. Nope:
$ perl -e 'print ~4294967295'
0
a
Test:
$temp=3D'196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conserved membraneprotein=
Sequence
:196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedmembrane protein';
print $temp, "\n";
#$name =3D $1;
$temp =3D ~s/'//g;
print $temp, "\n";
$temp=3D'196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conserved membraneprotein=
Sequence
:196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedmembrane protein';
$temp =3D s/'//g;
print $temp, "\n";
$temp=3D'196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conserved membraneprotein=
Sequence
:196818OVA_Chlre2_kg.scaffold_4000234YEE1\'conservedmembrane protein';
$temp =3D~ s/'//g;
print $temp, "\n";
Andy Bach
Systems Mangler
Internet: andy_bach@wiwb.uscourts.gov
VOICE: (608) 261-5738 FAX 264-5932
"Procrastination is like putting lots and lots of commas in the sentence =
of your life."
Ze Frank =
http://lifehacker.com/software/procrastination/ze-frank-on-p rocrastination-=
235859.php
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs