Overview
| Artifact ID: | e0ba12e4065feaabd6e462a163c62d38ced3fbaa |
|---|---|
| Ticket: | 218784ffffffffffffffffffffffffffffffffff
regexp hangs with non-greedy option in expanded RE |
| User & Date: | nobody on 2000-10-26 01:05:19 |
Changes
- assignee changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
OriginalBugID: 2117 Bug Version: 8.1 SubmitDate: '1999-05-21' LastModified: '1999-08-04' Severity: CRIT Status: Released Submitter: pat ChangedBy: stanton OS: Windows 98 Machine: X86 FixedDate: '1999-06-01' FixedInVersion: 8.2b1 ClosedDate: '2000-10-25' Name: Christopher Nelson Comments: Same behaviour on W98 and WNT with 8.1b2 and 8.1.0 ReproducibleScript: set fields {Name Birthdate Notes} set re "(?ix) # Ignore case (i), expanded syntax (x) ^ # Start at the start of the string ([join $fields |]) # Match and capture any field names : # followed by a colon \\s* # Optional white space after the colon (.*?) # Capture the rest of the line \\s* # excluding trailing whitespace $ # Use the whole line " ;# Can't comment after the " without a ; to # terminate the set command # Open the input file set fid [open redata.txt r] # While not done, read and process the next line while {! [eof $fid] } { set len [gets $fid line] switch -- $len { 0 { # Skip blank lines continue } -1 { # EOF break } } # See if we can parse this line if { ! [regexp $re $line whole field value] } { puts stderr "No field found in <<$line>>" continue } # Use case-insensitive regexp to match fields # We could do "set field [string toupper $field]" switch -regexp -- $field { (?i)NAME { set name $value lappend a(names) $name } (?i)BIRTHDATE { set a($name,dob) [clock scan $value] } (?i)NOTES { set a($name,notes) $value } default { puts "no match in switch" } } } close $fid Where redata.txt contains: Name: Fred Flintstone birthdate:4/1/01 notes: Member, water buffalo lodge name:Barney Rubble birthdate:5/15/09 notes: NOT the purple Barney! ObservedBehavior: If the second capture is "(.*?)", this script hangs. If I remove the non-greedy qualifier, it works (but value is left with trailing whitespace). This script works: set fields {Name Birthdate Notes} set line "Name: Fred Flintstone " # This works but leaves value with trailing white space set re "(?ix)^([join $fields |]):\\s*(.*)\\s*$" puts [regexp $re $line whole field value] puts "<<$value>>" # This tries to make (.*) non-greedy (so trailing white space is trimmed) set re "(?ix)^([join $fields |]):\\s*(.*?)\\s*$" puts [regexp $re $line whole field value] puts "<<$value>>" The only difference seems to be that the regexp isn't expanded. DesiredBehavior: Expanded format shouldn't cause a valid RE to hang Tcl I've forwarded this bug to Henry Spencer. 05/27/1999 11:23 - stanton - 06/01/1999 18:44 - stanton -Henry sent us a patch that fixes this problem. It has been applied to the CVS repository. - foundin changed to: "obsolete: 8.1"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "nobody"
- subsystem changed to: "43. Regexp"
- title changed to: "regexp hangs with non-greedy option in expanded RE"
- type changed to: "Bug"