Professional Web Applications Themes

regexp needed to split letters from numbers - Ruby

Hi -- On Sat, 27 Sep 2003, Thomas A. Reilly wrote: > I would appreciate it if someone could give me the regexp that it would > split the following: > for example - > "clonidine300 mg" into "clonidine 300 mg" > > I have a bunch of drug data where the dose had been typed together. Just to add to the list of ideas: in 1.8.0 you can use scanf: irb(main):016:0> require 'scanf' => false irb(main):017:0> str = "clonidine300 mg" => "clonidine300 mg" irb(main):018:0> name, dose, unit = str.scanf('%[\D]%d%s') => ["clonidine", 300, "mg"] the advantage of which is that ...

  1. #1

    Default Re: regexp needed to split letters from numbers

    Hi --

    On Sat, 27 Sep 2003, Thomas A. Reilly wrote:
    > I would appreciate it if someone could give me the regexp that it would
    > split the following:
    > for example -
    > "clonidine300 mg" into "clonidine 300 mg"
    >
    > I have a bunch of drug data where the dose had been typed together.
    Just to add to the list of ideas: in 1.8.0 you can use scanf:

    irb(main):016:0> require 'scanf'
    => false
    irb(main):017:0> str = "clonidine300 mg"
    => "clonidine300 mg"
    irb(main):018:0> name, dose, unit = str.scanf('%[\D]%d%s')
    => ["clonidine", 300, "mg"]

    the advantage of which is that it turns your dosage into an integer
    rather than a string. (But it doesn't handle the case where there are
    digits in the drug name.)


    David

    --
    David Alan Black
    home: [email]dblacksuperlink.net[/email]
    work: [email]blackdavshu.edu[/email]
    Web: [url]http://pirate.shu.edu/~blackdav[/url]


    dblack@superlink.net Guest

  2. #2

    Default Re: regexp needed to split letters from numbers

    On Sat, 27 Sep 2003 [email]dblacksuperlink.net[/email] wrote:
    > irb(main):016:0> require 'scanf'
    > => false
    Whoops, that's because I'd already required it in this session :-)


    David

    --
    David Alan Black
    home: [email]dblacksuperlink.net[/email]
    work: [email]blackdavshu.edu[/email]
    Web: [url]http://pirate.shu.edu/~blackdav[/url]


    dblack@superlink.net Guest

Similar Threads

  1. ORDER BY (numbers and letters)
    By Glen T in forum Coldfusion Database Access
    Replies: 18
    Last Post: October 10th, 05:59 PM
  2. Numbers or letters in a TextBox
    By PABLIN in forum ASP.NET Building Controls
    Replies: 1
    Last Post: August 28th, 04:30 AM
  3. Split Screen Game - Help Needed
    By wargghh in forum Macromedia Director 3D
    Replies: 1
    Last Post: August 26th, 10:26 AM
  4. regexp warning in String.split?
    By Chris Morris in forum Ruby
    Replies: 3
    Last Post: August 15th, 01:15 PM
  5. split alternative using regexp?
    By Thens in forum PERL Miscellaneous
    Replies: 4
    Last Post: July 31st, 10:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139