Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 16:19 jespanda: :/
- 16:19 jespanda: question
- 16:19 jespanda: if i am editing routes, i have /123-blah, but I just want /123, how do i get that?
- 16:21 wsong: k
- 16:21 ian: routes in what
- 16:21 ian: wsong: bye
- 16:21 ian: wait
- 16:21 ian: are you not saying goodbye
- 16:21 wsong: ?
- 16:21 wsong: oh
- 16:21 ian: I thought I was going to be super smart and call it before you said so
- 16:21 wsong: wrong window
- 16:21 jespanda: routes in ruby
- 16:21 ian: damnnnn
- 16:21 wsong: close call though
- 16:22 wsong: you wanna watch the game somewhere today, btw?
- 16:22 ian: matt is coming into town and we're supposed to hang out
- 16:22 ian: I dunno where or when
- 16:22 ian: still waiting to hear back
- 16:23 Asterism: oh fuck
- 16:23 Asterism: mali index patient came in on a bus
- 16:23 ian: mali index?
- 16:23 Asterism: bleeding the whole way, and misdiagnosed as typhoid
- 16:23 ian: oooo fuck
- 16:23 jAg: hahhahahahahahahahahahah.....fuck
- 16:24 Asterism: rip
- 16:24 Asterism: basically worst case scenario here
- 16:24 jespanda: mali index?
- 16:24 jespanda: anyone able to help with the route problem?
- 16:24 Asterism: patient zero
- 16:24 jespanda: news link
- 16:25 wsong: jespanda: are you just trying to change the string?
- 16:25 wsong: or do you mean in like rails or whatever
- 16:25 jespanda: yes
- 16:25 skimbrel: jespanda: ruby != rails
- 16:25 Asterism: it's worth noting that ebola's batting average against Americans being treated in American hospitals is south of 33%
- 16:25 jespanda: in ruby
- 16:25 Asterism: 0.33 I guess
- 16:25 wsong: oh
- 16:25 wsong: well, is the “-blah” part always the same length?
- 16:25 jespanda: no
- 16:25 wsong: you could just split on hyphens
- 16:25 jespanda: random srting
- 16:25 wsong: and just drop the last bit
- 16:25 Asterism: which leves to a bunch of reassuring/non-reassuring inferences
- 16:25 jespanda: random strings
- 16:25 skimbrel: what do you have, and what do you want
- 16:25 jespanda: i just want whatever digits are in the front
- 16:25 jespanda: i was trying to regex it
- 16:25 jAg: tropical diseases aren't nearly as effective against modern western medicine?!! COlor me shocked
- 16:25 jAg: "Forty-three people, including 10 health workers, who came into contact with her have been identified and isolated."
- 16:25 jespanda: but it spat out the id without the changes
- 16:25 skimbrel: /(\d+).+?/
- 16:25 Asterism: inference A) some of those weird ass experimental therapies actually work (not reassuring, since we're pretty much out)
- 16:26 skimbrel: then retrieve the first group
- 16:26 skimbrel: i forget how you get groups out of a match in rubby
- 16:26 Asterism: inference B) early contact tracing leading to early hospitalization significantly increases survival rate (kind of reassuring; these systems will be stressed in a major outbreak)
- 16:26 evan___ has joined (~Palaver@152.sub-70-208-91.myvzw.com)
- 16:26 Asterism: inference C) higher standards of pallative care significantly increases survival rate (pretty reassuring)
- 16:28 jespanda: to_s.gsub(/^\d*/, '')
- 16:28 jespanda: gsub(/^\d*/, '')
- 16:28 jespanda: is what i have
- 16:28 skimbrel: are you trying to do it in place?
- 16:28 jespanda: i would expect to at least remove part of the string
- 16:28 jespanda: i have 1234-abcd
- 16:28 wsong: i think you need square brackets
- 16:28 wsong: if you’re trying to do a character class
- 16:29 jespanda: when i did that, the entire string just disappears
- 16:30 wsong: how about
- 16:30 jespanda: hence my confusion
- 16:30 wsong: to_s.gsub(/[^0-9]/, ‘’)
- 16:30 wsong: i don’t know ruby, but i think gsub will match on a character-by-character basis
- 16:31 wsong: yeah
- 16:31 jespanda: nope, i still get the full string
- 16:31 evan___ has left IRC (Ping timeout: 255 seconds)
- 16:31 wsong: huh
- 16:31 wsong: i’m trying it out here:
- 16:31 wsong: http://repl.it/languages/Ruby
- 16:31 steggybot__: repl.it
- 16:32 wsong: and this does the right thing
- 16:32 wsong: "/123-blah".to_s.gsub(/[^\d]/, '')
- 16:32 wsong: that should be equivalent to this, btw
- 16:32 wsong: "/123-blah".gsub(/[^0-9]*/, '')
- 16:32 wsong: is that what you’re entering?
- 16:32 wsong: keep in mind that that’ll return the string you want
- 16:32 wsong: the original string will, i think, be unmodified
- 16:32 wsong: (ruby has immutable strings, right?)
- 16:32 jespanda: i start with /boo/:id
- 16:32 jespanda: i am feeding it into bar(:id)
- 16:33 jespanda: and i want bar to do the transformation for me
- 16:33 skimbrel: and which piece do you want out
- 16:33 wsong: well, do you want to actually modify the string
- 16:33 wsong: or do you want bar to return a string
- 16:33 wsong: if ruby’s anything like python, you can’t modify strings
- 16:34 wsong: anyways, i gotta go into a meeting, but good luck
- 16:34 jespanda: new_id = '%{id}'.to_s.gsub(/[^0-9]/, ‘’)
- 16:34 jespanda: is what i currently have
- 16:34 jespanda: where new_id is hopefully the sanitized version
- 16:34 skimbrel: can we describe the problem in english
- 16:35 skimbrel: and then construct the appropriate code
- 16:35 skimbrel: you have: a string of the form “123-abc-def”
- 16:35 skimbrel: and you want “123”?
- 16:35 skimbrel: or you want “-abc-def”
- 16:36 jespanda: i want 123
- 16:36 jespanda: i just want the numbers
- 16:36 whunt has left IRC (Ping timeout: 272 seconds)
- 16:37 skimbrel: ok
- 16:37 skimbrel: you need to use a group
- 16:38 jespanda: why is that?
- 16:38 skimbrel: because groups capture the things you match with them
- 16:38 skimbrel: and then you can extract that matched substring from the match object:
- 16:38 skimbrel: and you shouldn’t be using gsub
- 16:38 Asterism: what's wrong with /^(\d+)-\S+$/
- 16:38 skimbrel: instead of trying to delete things you don’t care about, match the thing you do want
- 16:39 skimbrel: yes, exactly that thing asterism just said
- 16:39 Asterism: and yeah, you want string#match
- 16:39 skimbrel: int_id = /(\d+).*/.match(id)[1]
- 16:39 skimbrel: http://www.ruby-doc.org/core-2.1.3/Regexp.html#method-i-match
- 16:39 steggybot__: Class: Regexp (Ruby 2.1.3)
- 16:39 Asterism: that too
- 16:42 Asterism: alright
- 16:42 Asterism: that's it
- 16:42 Asterism: bill kirstol has gone off the deep end
- 16:42 Asterism: https://twitter.com/BillKristol/status/524920942049648640
- 16:43 skimbrel: also jespanda you shouldn’t need to use “%{id}” if id is already a string
- 16:43 skimbrel: rofl, cheney-giuliani
- 16:44 whunt has joined (~whunt@216.2.42.42)
- 16:44 heidi has joined (~heidi@216.2.42.42)
- 16:45 jespanda: skimbrel, i am getting this error now
- 16:45 jespanda: undefined method `[]' for nil:NilClass
- 16:45 Asterism: jespanda: okay, just use this
- 16:45 Asterism: http://rubular.com/
- 16:45 steggybot__: Rubular: a Ruby regular expression editor and tester
- 16:46 skimbrel: if you got nil then it means your match didn't.
- 16:46 Asterism: for the record, skimbrel's code works fine in 1.9.3
- 16:46 skimbrel: what the fuck did they change in 2.0?
- 16:46 Asterism: um
- 16:47 Asterism: almost nothing
- 16:47 Asterism: so i'm going to say that it's the string's fault
- 16:47 skimbrel: oh heh
- 16:47 jAg: man, Asterism, i want whatever he's smoking
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement