String gsub last '/\\%[0-8a-fA-F][0-8a-fA-F]/ match does not sub

Ruby Versions:

ruby 1.6.7 (2002-03-01) [i686-cygwin] and

ruby 1.7.3 (2002-09-25) [i386-cygwin]

Platform: Windows 2000 SP3

I am using string.gsub to replace “/%[0-8a-fA-F][0-8a-fA-F]/” with “_”.

The following two gsub is to prove that gsub does sub ‘%29’

“Simple+SNMP+%28s2nmp%29”.gsub( /%2./ , “_” )
—> “Simple+SNMP+s2nmp

“Simple+SNMP+%28s2nmp%29”.gsub( /%\d\d/ , “_” )
—> “Simple+SNMP+s2nmp

The following gsub is what I would need to use in a program

“Simple+SNMP+%28s2nmp%29”.gsub( /%[0-8a-fA-F][0-8a-fA-F]/ , “_” )
—> “Simple+SNMP+_s2nmp%29”

Here is some other strings that did not gsub correctly

ruby-aes+%28rijndael%29 “ruby-aes+_rijndael%29”

RDE%28Ruby+Development+Environment%29
"RDE_Ruby+Development+Environment%29"

eval.rb+%28ANSI%29 “eval.rb+_ANSI%29”

Rubonix+%3A%29 “Rubonix+_%29”

Ruby%2FOCI8+%28oracle%29 “Ruby_OCI8+_oracle%29”

RUDL+%28wraps+SDL%29 “RUDL+_wraps+SDL%29”

ruby-termios+%28serial+ports%29 “ruby-termios+_serial+ports%29”

Simple+SNMP+%28s2nmp%29 “Simple+SNMP+_s2nmp%29”

Quanty+%28units%29 “Quanty+_units%29”

Programmieren+mit+Ruby+%28dpunkt.Verlag+Buch%29
"Programmieren+mit+Ruby+_dpunkt.Verlag+Buch%29"

Programming+Ruby+%28Hunt%2FThomas%29
"Programming+Ruby+_Hunt_Thomas%29"

Ruby+Reference+Manual+%28Windows+HTML+Help%29
"Ruby+Reference+Manual+_Windows+HTML+Help%29"

Ruby+Reference+Manual+%2B+RDP+%28HTML+Help%29
"Ruby+Reference+Manual+_+RDP+_HTML+Help%29"

Ruby+glossary+%28en%2C+RD%29 “Ruby+glossary+en+RD%29”

Ruby+Reference+Manual+%28RD%29 “Ruby+Reference+Manual+_RD%29”

Ruby+Reference+Manual+%28Texinfo+English%29
"Ruby+Reference+Manual+_Texinfo+English%29"

Ruby+Reference+Manual+%28Texinfo%29
"Ruby+Reference+Manual+_Texinfo%29"

ObjectDay2000+Ruby+Session%28pdf%2C+Japanese%29
"ObjectDay2000+Ruby+Session_pdf_+Japanese%29"

robert_linder_2000@yahoo.com

I am using string.gsub to replace “/%[0-8a-fA-F][0-8a-fA-F]/” with “_”.

The following gsub is what I would need to use in a program

“Simple+SNMP+%28s2nmp%29”.gsub( /%[0-8a-fA-F][0-8a-fA-F]/ , “_” )
—> “Simple+SNMP+_s2nmp%29”

Why would it replace %29? your matching 0-8, not 0-9.

···

On Thursday, September 26, 2002, at 07:13 PM, Robert Linder wrote:

Me , Dummy.

I was thinking of Hex ranges, not base 10

Thanks

robert_linder_2000@yahoo.com
908-319-0122

···

-----Original Message-----
From: Ryan Davis [mailto:ryand@zenspider.com]
Sent: Friday, September 27, 2002 1:39 AM
To: ruby-talk ML
Subject: Re: String gsub last '/\%[0-8a-fA-F][0-8a-fA-F]/ match does
not sub

On Thursday, September 26, 2002, at 07:13 PM, Robert Linder wrote:

I am using string.gsub to replace “/%[0-8a-fA-F][0-8a-fA-F]/” with
“_”.

The following gsub is what I would need to use in a program

“Simple+SNMP+%28s2nmp%29”.gsub( /%[0-8a-fA-F][0-8a-fA-F]/ , “_” )
—> “Simple+SNMP+_s2nmp%29”

Why would it replace %29? your matching 0-8, not 0-9.

The other option is to use cgi-lib to unescape the string and use a
regex to replace any character you don’t want to see:

require ‘cgi-lib’

CGI::unescape(str).gsub(/[^a-zA-Z0-9_+-]/n) { ‘_’ }

···

Robert Linder (robert_linder_2000@yahoo.com) wrote:

Me , Dummy.

I was thinking of Hex ranges, not base 10


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04