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

···

--
Posted via http://www.ruby-forum.com/.

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.

···

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

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@marnen.org
--
Posted via http://www.ruby-forum.com/\.

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

···

On Nov 30, 2009, at 9:07 PM, J. mp wrote:

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/\.

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+)\)\)\+\+

···

On Tue, Dec 1, 2009 at 10:07 AM, J. mp <joaomiguel.pereira@gmail.com> wrote:

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/\.

--
Liu Lantao
College of Information Science and Technology, Beijing Normal University
EMAIL: liulantao ( at ) gmail ( dot ) com ;
WEBSITE: http://www.liulantao.com/ .
------

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/.

Ruby Bucket wrote:

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

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

Best,

···

--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
--
Posted via http://www.ruby-forum.com/\.

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@marnen.org
--
Posted via http://www.ruby-forum.com/\.