one more regular expression, please

J

J. mp

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
 
D

David Masover

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

Marnen Laibow-Koser

J. mp said:
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
(e-mail address removed)
 
J

J. mp

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

Marnen Laibow-Koser

J. mp said:
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
(e-mail address removed)
 
L

Liu Lantao

[Note: parts of this message were removed to make it a legal post.]

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

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


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top