Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2000-11-15
21:44 • Closed ticket [219374ffff]: non-greedy quantifiers break capturing parens pl... artifact: 4293a1e108 user: dkf
2000-10-26
05:11 • New ticket [219374ffff]. artifact: 994d059a5b user: nobody

non-greedy quantifiers break capturing parens

Closed / Duplicate219374ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 05:11:48
OriginalBugID: 5996 Bug
Version: 8.4a1
SubmitDate: '2000-07-10'
LastModified: '2000-10-25'
Severity: LOW
Status: UnAssn
Submitter: techsupp
OS: Linux-Red Hat
OSVersion: Tcl 8.3, 8.4a1, Windows 98 and RedHat Linux 6.x
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'


Name:
Vadim Nasardinov

ReproducibleScript:
set str "start <s> continue <s> in both regexes, parens should capture up to here"

regexp {.*<s>(.*)} $str match parens

puts "
Greedy match (works ok):
  match: >$match<
  parens: >$parens<
"

regexp {.*?<s>(.*)} $str match parens

puts "
Non-greedy match (p2 does not get set):
  match: >$match<
  parens: >$parens<
"

ObservedBehavior:
Using a non-greedy quantifier causes breaks capturing parens.

DesiredBehavior:
The above code snippet should produce the following output:

Greedy match (works ok):
  match: >start <s> continue <s> in both regexes, parens should capture up to here<
  parens: > in both regexes, parens should capture up to here<

Non-greedy match (p2 does not get set):
  match: >start <s><
  parens: > continue <s> in both regexes, parens should capture up to here<
dkfplain2000-11-15 21:44:52
This is known behaviour of the regexp engine (the first quantifier in a regexp sets the greediness for the whole regexp) though I've yet to see a convincing explanation of why this is correct...
Log in (anonymous is fine) to add a comment.