re question

  • Thread starter =?ISO-8859-1?Q?Sch=FCle_Daniel?=
  • Start date
?

=?ISO-8859-1?Q?Sch=FCle_Daniel?=

Hello all,

I didn't found more appropriate news group for
this question, please let me know if there is ng with
regular expression as its main topic

I am trying to construct a case where a greedy and
non greedy operation produce different result.
I dont see the difference between 'a??b' and 'a?b'
As far I understand is that ? will first try to match a
(it's greedy) and only if it fails then it step back
and lets a unmatched. The other doesn't match a at first,
only if the pattern fails to match it steps back and match a.

But don't they do eventually the same thing?
Can someone provide an example where 2 patterns yield
different results.

Regards, Daniel
 
S

Steve Holden

Schüle Daniel said:
Hello all,

I didn't found more appropriate news group for
this question, please let me know if there is ng with
regular expression as its main topic

I am trying to construct a case where a greedy and
non greedy operation produce different result.
I dont see the difference between 'a??b' and 'a?b'
As far I understand is that ? will first try to match a
(it's greedy) and only if it fails then it step back
and lets a unmatched. The other doesn't match a at first,
only if the pattern fails to match it steps back and match a.

But don't they do eventually the same thing?
Can someone provide an example where 2 patterns yield
different results.

regards
Steve
 
A

attn.steven.kuo

Schüle Daniel wrote:

(snipped)
I am trying to construct a case where a greedy and
non greedy operation produce different result.
I dont see the difference between 'a??b' and 'a?b'
As far I understand is that ? will first try to match a
(it's greedy) and only if it fails then it step back
and lets a unmatched. The other doesn't match a at first,
only if the pattern fails to match it steps back and match a.

But don't they do eventually the same thing?
Can someone provide an example where 2 patterns yield
different results.

Perhaps this sheds some light

Yields:

['a', 'a', 'ab', 'a', ''] ['', '', '', 'b', '', '']
 

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
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top