Regular Expression help

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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
amit hetawal [ Fr, 02 März 2007 21:59 ] [ ID #1646102 ]

Re: Regular Expression help

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"


<br><font size=2 face="Courier New">>$temp = ~s/^'$//g;<br>
</font>
<br><font size=2 face="Courier New">Remove the '^' and '$' anchors. what your expression is expecting to work on is a string that consists solely of a single-quote.</font>
<br>
<br><font size=2 face="Courier New">Try</font>
<br>
<br><font size=2 face="Courier New">$temp =~ s/'//g;</font>
<br>
<br><font size=2 face="Courier New"><br>
Deane Rothenmaier<br>
Systems Architect<br>
Walgreens Corp.<br>
847-914-5150<br>
<br>
"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</font>
--=_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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1526188374==--
Deane.Rothenmaier [ Fr, 02 März 2007 22:05 ] [ ID #1646103 ]

Re: Regular Expression help

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 [at] walgreens.com
<Deane.Rothenmaier [at] 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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
amit hetawal [ Fr, 02 März 2007 22:09 ] [ ID #1646104 ]

Re: Regular Expression help

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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Kevin Roland Viel [ Fr, 02 März 2007 22:12 ] [ ID #1646105 ]

Re: Regular Expression help

> 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 [at] 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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Andy_Bach [ Fr, 02 März 2007 22:17 ] [ ID #1646106 ]

RE: Regular Expression help

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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
JavierMoreno [ Fr, 02 März 2007 22:18 ] [ ID #1646107 ]

Re: Regular Expression help

$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 [at] 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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Andy_Bach [ Fr, 02 März 2007 22:19 ] [ ID #1646108 ]

Re: Regular Expression help

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 <kviel [at] emory.edu> 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 [at] listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
amit hetawal [ Fr, 02 März 2007 22:20 ] [ ID #1646109 ]

Re: Regular Expression help

$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 [at] 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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Andy_Bach [ Fr, 02 März 2007 22:26 ] [ ID #1646110 ]
Perl » gmane.comp.lang.perl.active-perl » Regular Expression help

Vorheriges Thema: Perl and Daylight Saving Time on Windows
Nächstes Thema: exiting an eval block inside a loop?