From: J. mp on 30 Nov 2009 21:07 Hi, I really can't figure out how regular expressions work, and since I don't use them frequently is easier to ask... I have the follwow string ++((100))++askjasdjksjdkasdkjk++((200))++skdjsjd I need a reg expression that extracts only the first number inside the first ++(( ))++ and ignore the rest..., in this case I need to return 100 thanks -- Posted via http://www.ruby-forum.com/.
From: David Masover on 30 Nov 2009 21:55 On Monday 30 November 2009 08:07:26 pm J. mp wrote: > I have the follwow string > > ++((100))++askjasdjksjdkasdkjk++((200))++skdjsjd > > I need a reg expression that extracts only the first number inside the > first ++(( ))++ and ignore the rest..., in this case I need to return > 100 Since I can't figure out why you'd ever want to do that in a real app, I have to ask: Is this a homework assignment? Well, I'd rather not assume, so I'll give you a partial answer: Regular expressions don't return things, they match things. You can't write a regular expression (that I know of) which will match only what you're asking for, unless you assume things about that specific string. Especially in homework, assuming things like that is a Bad Idea. There is a solution, and it includes regular expressions, but they are not the whole story.
From: Marnen Laibow-Koser on 30 Nov 2009 22:05 J. mp wrote: > Hi, > > I really can't figure out how regular expressions work, So you're giving up and expecting us to do your work for you? Come on! You could at least try. > and since I > don't use them frequently is easier to ask... Yes, ask. Ask irb. Ask http://www.rubular.com . But don't you dare ask this list until you've made an attempt. Begging others to write code because you're too lazy to try is not cool! > > I have the follwow string > > ++((100))++askjasdjksjdkasdkjk++((200))++skdjsjd > > I need a reg expression that extracts only the first number inside the > first ++(( ))++ and ignore the rest..., in this case I need to return > 100 > > > thanks Best, -- Marnen Laibow-Koser http://www.marnen.org marnen(a)marnen.org -- Posted via http://www.ruby-forum.com/.
From: J. mp on 30 Nov 2009 22:23 you're both right. That was a dumb question. I will try to find it by myself. Thank you. -- Posted via http://www.ruby-forum.com/.
From: Marnen Laibow-Koser on 1 Dec 2009 00:40 J. mp wrote: > > you're both right. That was a dumb question. I will try to find it by > myself. Thank you. Good luck. If you get stuck, help is available. Regexes are lots of fun once you understand them! Best, -- Marnen Laibow-Koser http://www.marnen.org marnen(a)marnen.org -- Posted via http://www.ruby-forum.com/.
|
Next
|
Last
Pages: 1 2 Prev: Searching Text for Multiple Matches Next: Pell's equation solver in Ruby |