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