Regexp: getting the first found

A

Ahmad Azizan

Hello,

I'm having some problem comprehending the regexp for my current need.

Example input (2 scenario):

1.

<<
/Filter
/FlateDecode
/Length 4169stream
blablabla
endstream

<< >>

2.

<</Filter/FlateDecode/Length 4169>>
stream
blablabla
endstream

<< >>

I've trying to get the string after the string /Filter and the first
seen ">>" by using this regexp: /<<(.*)\/Filter(.*)>>/im

The problem is that, there is two >> in the input and the regexp takes
until the last >> it detected. How can I make it to get only until the
first >> that it detects ?

Thank you in advance
 
R

Ralph Shnelvar

Ahmad,

Newbie here so take what I have to say with a grain of salt.

Your pattern is "greedy". To turn it into a lazy pattern add a
question mark thusly ...

/<<(.*)\/Filter(.*?)>>/

(untested)

Ralph


Monday, November 9, 2009, 2:43:12 AM, you wrote:

AA> Hello,

AA> I'm having some problem comprehending the regexp for my current need.

AA> Example input (2 scenario):

AA> 1.

AA> <<
AA> /Filter
AA> /FlateDecode
AA> /Length 4169AA> stream
AA> blablabla
AA> endstream

AA> << >>

AA> 2.

AA> <</Filter/FlateDecode/Length 4169>>
AA> stream
AA> blablabla
AA> endstream

AA> << >>

AA> I've trying to get the string after the string /Filter and the first
seen ">>>" by using this regexp: /<<(.*)\/Filter(.*)>>/im

AA> The problem is that, there is two >> in the input and the regexp takes
until the last >>> it detected. How can I make it to get only until the
first >>> that it detects ?

AA> Thank you in advance
 
A

Ahmad Azizan

Ralph said:
Ahmad,

Newbie here so take what I have to say with a grain of salt.

Your pattern is "greedy". To turn it into a lazy pattern add a
question mark thusly ...

/<<(.*)\/Filter(.*?)>>/

(untested)

Ralph

Thanks for the reply.

Basically that's what I need. Thanks for pointing me towards new options
like "greedy". Because of that, I've been able to find new Ruby regex
reference like
http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm

Really appreciate that, thanks
 

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,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top