Home > Archive > PERL Beginners > September 2004 > regex help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Colin Johnstone 2004-09-24, 3:56 am |
| Gidday all,
Im trying to write a regex to convert spaces to underscores and ampersands =
to 'and' can someone help.
$safeString =3D "News & Events";
$safeString =3D~ s/&/and/g;
$safeString =3D~ s/\s/_/g;
Regards
Colin=20
This E-Mail is intended only for the addressee. Its use is limited to that
intended by the author at the time and it is not to be distributed without =
the
author's consent. Unless otherwise stated, the State of Queensland accepts =
no
liability for the contents of this E-Mail except where subsequently confirm=
ed in
writing. The opinions expressed in this E-Mail are those of the author and =
do
not necessarily represent the views of the State of Queensland. This E-Mail=
is
confidential and may be subject to a claim of legal privilege.
If you have received this E-Mail in error, please notify the author and del=
ete this message immediately.
| |
| Colin Johnstone 2004-09-24, 3:56 am |
| I worked it out myself
$safeString =3D "News & Events";
$safeString =3D~ s!&!and!g;
$safeString =3D~ s!\s!_!g;
thank you
Colin
-----Original Message-----
From: Johnstone, Colin=20
Sent: Friday, September 24, 2004 3:32 PM
To: beginners@perl.org
Subject: regex help
Gidday all,
Im trying to write a regex to convert spaces to underscores and =
ampersands to 'and' can someone help.
$safeString =3D "News & Events";
$safeString =3D~ s/&/and/g;
$safeString =3D~ s/\s/_/g;
Regards
Colin=20
This E-Mail is intended only for the addressee. Its use is limited to =
that
intended by the author at the time and it is not to be distributed =
without the
author's consent. Unless otherwise stated, the State of Queensland =
accepts no
liability for the contents of this E-Mail except where subsequently =
confirmed in
writing. The opinions expressed in this E-Mail are those of the author =
and do
not necessarily represent the views of the State of Queensland. This =
E-Mail is
confidential and may be subject to a claim of legal privilege.
If you have received this E-Mail in error, please notify the author and =
delete this message immediately.
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Ramprasad A Padmanabhan 2004-09-24, 3:56 am |
| On Fri, 2004-09-24 at 11:01, Johnstone, Colin wrote:
> Gidday all,
>
> Im trying to write a regex to convert spaces to underscores and ampersands to 'and' can someone help.
>
> $safeString = "News & Events";
> $safeString =~ s/&/and/g;
> $safeString =~ s/\s/_/g;
>
> Regards
>
> Colin
>
What you have written is perfectly fine .. why do you think it will not
work ?
you may consider however writing '\&' instead of '&'
Bye
Ram
| |
| Raymond Raj 2004-09-24, 3:56 am |
| Hi!
what's problem in these regular expressions.. every thing correct!
do you need to convert one or more than one match into single replacement
then regexp should be
$safeString =~ s/\s+/_/g;
-----Original Message-----
From: Johnstone, Colin [mailto:Colin.Johnstone@det.qld.gov.au]
Sent: Friday, September 24, 2004 11:02 AM
To: beginners@perl.org
Subject: regex help
Gidday all,
Im trying to write a regex to convert spaces to underscores and ampersands
to 'and' can someone help.
$safeString = "News & Events";
$safeString =~ s/&/and/g;
$safeString =~ s/\s/_/g;
Regards
Colin
This E-Mail is intended only for the addressee. Its use is limited to that
intended by the author at the time and it is not to be distributed without
the
author's consent. Unless otherwise stated, the State of Queensland accepts
no
liability for the contents of this E-Mail except where subsequently
confirmed in
writing. The opinions expressed in this E-Mail are those of the author and
do
not necessarily represent the views of the State of Queensland. This E-Mail
is
confidential and may be subject to a claim of legal privilege.
If you have received this E-Mail in error, please notify the author and
delete this message immediately.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Colin Johnstone 2004-09-24, 3:56 am |
| Thank you I musthave just coded something wrong, your right they do =
work. Sorry!
-----Original Message-----
From: Raymond Raj [mailto:raymond@shafika.vetri.com]
Sent: Friday, September 24, 2004 3:55 PM
To: Johnstone, Colin; beginners@perl.org
Subject: RE: regex help
Hi!
what's problem in these regular expressions.. every thing correct!
do you need to convert one or more than one match into single =
replacement
then regexp should be
$safeString =3D~ s/\s+/_/g;
-----Original Message-----
From: Johnstone, Colin [mailto:Colin.Johnstone@det.qld.gov.au]
Sent: Friday, September 24, 2004 11:02 AM
To: beginners@perl.org
Subject: regex help
Gidday all,
Im trying to write a regex to convert spaces to underscores and =
ampersands
to 'and' can someone help.
$safeString =3D "News & Events";
$safeString =3D~ s/&/and/g;
$safeString =3D~ s/\s/_/g;
Regards
Colin
This E-Mail is intended only for the addressee. Its use is limited to =
that
intended by the author at the time and it is not to be distributed =
without
the
author's consent. Unless otherwise stated, the State of Queensland =
accepts
no
liability for the contents of this E-Mail except where subsequently
confirmed in
writing. The opinions expressed in this E-Mail are those of the author =
and
do
not necessarily represent the views of the State of Queensland. This =
E-Mail
is
confidential and may be subject to a claim of legal privilege.
If you have received this E-Mail in error, please notify the author and
delete this message immediately.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
|
|
|
|
|