regex - Extracting portion of a file within braces using regular expression -
i have file of following form :
some text more text . . . . . . data { 1 2 3 5 yes 10 2 3 4 5 no 11 } text text
i want extract data
portion of file using regular expression using following procedure:
proc extractdata {filename} { set sgd [open $filename r] set sgdcontents [read $sgd] regexp "data \\{(?.*)\\}" $sgdcontents -> data puts $data }
but giving following error:
couldn't compile regular expression pattern: quantifier operand invalid
i not able figure out wrong regular expression. highly appreciated.
use regular expression
regexp {data \{(.*)\}} $sgdcontents wholematch submatch puts $submatch
wholematch
matches entire pattern. in case is
data { 1 2 3 5 yes 10 2 3 4 5 no 11 }
and submatch
matches content inside braces below:
1 2 3 5 yes 10 2 3 4 5 no 11
Comments
Post a Comment