Code Comments
Programming Forum and web based access to our favorite programming groups.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.
Post Follow-up to this messageI 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>
Post Follow-up to this messageOn 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
Post Follow-up to this messageHi! 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>
Post Follow-up to this messageThank 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>
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.