One more regular expression, please

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

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.

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
[email protected]

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
[email protected]

/[^+]++((([0-9]+)))++./

you’re both right. That was a dumb question. I will try to find it by
myself. Thank you.

Ruby Bucket wrote:

/[^+]++((([0-9]+)))++./

Not quite. Anyway, don’t spoon-feed the lazy. :slight_smile:

Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]

extractor = Regexp.new(’++(((\d+)))++’)
extractor.match will extract all the ++(123)++ like parts and extract
all
123s into an array,
if the string start with ++, try
^++(((\d+)))++