|
From: tunity on 24 Jun 2008 14:36 I am using the following regular expression to tokenize a string into words. It works fine but it also gets rid of the spaces that I would like to keep. I only need them if they are within single quotes but it is fine if all spaces are preserved. Is there a way to do this? set str {decl a := char 'hello there'; } regexp -all -inline {\S+} $str
From: Glenn Jackman on 24 Jun 2008 14:55 At 2008-06-24 02:36PM, "tunity" wrote: > I am using the following regular expression to tokenize a string into > words. It works fine but it also gets rid of the spaces that I would > like to keep. I only need them if they are within single quotes but it > is fine if all spaces are preserved. > > Is there a way to do this? > > > set str {decl a := char 'hello there'; } > regexp -all -inline {\S+} $str I think of CSV format when I hear "split on X except between quotes", so: package require csv set str {decl a := char 'hello there'; } set tokens [csv::split $str { } '] http://tcllib.sourceforge.net/doc/csv.html -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous
From: Neil Madden on 24 Jun 2008 20:54 tunity wrote: > I am using the following regular expression to tokenize a string into > words. It works fine but it also gets rid of the spaces that I would > like to keep. I only need them if they are within single quotes but it > is fine if all spaces are preserved. > > Is there a way to do this? > > > set str {decl a := char 'hello there'; } > regexp -all -inline {\S+} $str set tokens [split $str] -- Neil
From: Arjen Markus on 25 Jun 2008 03:07 On 25 jun, 02:54, Neil Madden <n...(a)cs.nott.ac.uk> wrote: > tunity wrote: > > I am using the following regular expression to tokenize a string into > > words. It works fine but it also gets rid of the spaces that I would > > like to keep. I only need them if they are within single quotes but it > > is fine if all spaces are preserved. > > > Is there a way to do this? > > > set str {decl a := char 'hello there'; } > > regexp -all -inline {\S+} $str > > set tokens [split $str] > > -- Neil That won't work: the quotes are "apostrophes" ('), not quotation marks ("). Regards, Arjen
From: suchenwi on 25 Jun 2008 03:36 On 25 Jun., 09:07, Arjen Markus <arjen.mar...(a)wldelft.nl> wrote: > > > set str {decl a := char 'hello there'; } > > > regexp -all -inline {\S+} $str > > > set tokens [split $str] > That won't work: the quotes are "apostrophes" ('), not quotation > marks ("). But if the language does not contain quotes, or has them in similar meaning with apostrophes (like XML attributes), it might indeed make sense to string map {' \"}
|
Next
|
Last
Pages: 1 2 Prev: Parsing C and ASTs and tcllib's grammar_me Next: mod_tcl with apache 2.2 |