Re: Regular Expression question



On 6/30/07, Peter Seebach <seebs@xxxxxxxxx> wrote:
In message <0df4a451b19810ff6e06f11725324591@xxxxxxxxxxxxxx>, Al Cholic writes:
>Im working with regular expressions and I cant quite understand how the
>"13" is extracted from the string.
>Here is the irb output:
>irb(main):005:0> "(13)"[1..-2].to_i
>=> 13
>I dont understadn how the [1..-2] parameter removes the parenthases from
>the string.

"(13)"[0] = "("
"(13)"[1] = "1"
"(13)"[2] = "3"
"(13)"[3] = ")"

"(13)"[-1] = ")"
"(13)"[-2] = "3"
"(13)"[-3] = "1"
"(13)"[-4] = "("
Maybe it would not hurt to add a little clarification, albeit the fact
that your didactic simplification has worked very well :). Especially
as this concerns a FAQ

In reality
"(13)"[0] => ?( which equals 40
and
"(13)"[0..0] => "("

Cheers
Robert
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck

.



Relevant Pages

  • Re: Lots of help needed urgently
    ... will reveal the passwords that are usually displayed on-screen as a string ... of asterisks. ... > him for help `cos I cant send him an email. ... > COME ON Guys `n Gals help an old dumbass out of this ...
    (microsoft.public.security)
  • Re: Concatenate field as PK
    ... Prov, Cant, Dist, Bloq, Sect and NumParc. ... CodSig (string) ... NumPar (string) ...
    (microsoft.public.access.forms)
  • Re: function to change metric measurements
    ... i requre a little bit of guidance and help to right a simple function ... by a string or value to show that i want the result converting in to ... even though i passing the mm's to the function as a number i wish it to ... I know this should be easy but i just cant seem how i should structure my ...
    (microsoft.public.excel.worksheet.functions)
  • function to change metric measurements
    ... a string or value to show that i want the result converting in to ... I know this should be easy but i just cant seem how i should structure my ... as i done something similar for inches and passing the factor of the inches ...
    (microsoft.public.excel.worksheet.functions)
  • Re: String.replaceAll wont work :s
    ... It is very useful to know regular expressions, but in case you cant ... get the hang of them, i have this simple replace all method that ... public static String replaceAll(String text, String repl, String ...
    (comp.lang.java.help)