-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Richard Lionheart wrote: | Hi All, | | The following Ruby script displays use of a pattern to remove a superfluous | backslash in a string if present. It works as intended with two "toy" | situations, but fails when applied to an environment string running under | Windows. | | Can anyone tell me where I erred? | | TIA, | Richard | | ============ Ruby pgm =========== | | # Executed under Windows 2000 | | s1 = "ab\\\\" | puts "s1 before: \"#{s1}\" (two backslashes)" | s1.chop! if s1.reverse =~ /^\\\\/ | puts "s1 after: \"#{s1}\" (redced to a single backslash)" | | s2 = "ab\\" | puts "s2 before: \"#{s2}\" (single backslash)" | s2.chop! if s2.reverse =~ /^\\\\/ | puts "s2 after: \"#{s2}\" (single backslash, undisturbed)" | | s3 = ENV["UserProfile"] | puts "s3: \"#{s3}\"" | sCookiesPath = s3 + "\\" | puts "Cookies path before: \"#{sCookiesPath}\" (single backslash)" | sCookiesPath.chop! if sCookiesPath.reverse !~ /^\\\\/ | puts "Cookies path after: \"#{sCookiesPath}\" (single backslash removed - | why)" | | <<'OUTPUT' | |>rubyw PatternsTest.rb | | s1 before: "ab\\" (two backslashes) | s1 after: "ab\" (redced to a single backslash) | s2 before: "ab\" (single backslash) | s2 after: "ab\" (single backslash, undisturbed) | s3: "G:\Documents and Settings\RLMuller" | Cookies path before: "G:\Documents and Settings\RLMuller\" (single | backslash) | Cookies path after: "G:\Documents and Settings\RLMuller" (single backslash | removed - why) | |>Exit code: 0 Was that a trick question ? ;) kaspar semantics & semiotics code manufacture www.tua.ch/ruby -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFA7lucFifl4CA0ImQRAgiYAJ9jtzZpvwR2RkWukKIHpJvtom+NQgCgpqO9 HoUWXlqb6bC4Y5pCP6ondQI= =FwF7 -----END PGP SIGNATURE-----