From: Keith on 11 Mar 2010 14:14 I need to use regexp to extract a string in the following varying formats: 851.1000 35.20 1145.20 21.1 There is always a . in the string with a number before and after the decimal. Using regexp how can a find a match if the . is in the string? set x 851.1000 regexp {\d\d\d\.\d\d\d\d\} $x output will work, but I would like to have the entire string extracted if it meets any of the above examples. regexp {??\.??} $x output What would be the format for matching using regexp? -- Best Regards, Keith http://home.comcast.net/~kilowattradio/ I'm Your Huckle Berry http://www.youtube.com/watch?v=KfbAFgD2mLo
From: Aric Bills on 11 Mar 2010 15:28 On 11 mar, 12:14, Keith <kilowattra...(a)use-reply-to.invalid> wrote: > I need to use regexp to extract a string in the following varying > formats: > > 851.1000 > 35.20 > 1145.20 > 21.1 > > There is always a . in the string with a number before and after the > decimal. Using regexp how can a find a match if the . is in the string? > > set x 851.1000 > regexp {\d\d\d\.\d\d\d\d\} $x output > > will work, but I would like to have the entire string extracted if it > meets any of the above examples. > > regexp {??\.??} $x output > > What would be the format for matching using regexp? > > -- > Best Regards, Keithhttp://home.comcast.net/~kilowattradio/ > I'm Your Huckle Berryhttp://www.youtube.com/watch?v=KfbAFgD2mLo I think the pattern you're looking for is {\d+\.\d+}. That will match one or more digits followed by a period followed by one or more digits. If you want to only match strings that consist entirely of that pattern (i.e. disallow strings such as "my favorite radio station is 101.9 FM") you could use the pattern {^\d+\.\d+$} instead.
From: Alexandre Ferrieux on 11 Mar 2010 16:22 On Mar 11, 8:14 pm, Keith <kilowattra...(a)use-reply-to.invalid> wrote: > I need to use regexp to extract a string in the following varying > formats: > > 851.1000 > 35.20 > 1145.20 > 21.1 > > There is always a . in the string with a number before and after the > decimal. Using regexp how can a find a match if the . is in the string? > > set x 851.1000 > regexp {\d\d\d\.\d\d\d\d\} $x output > > will work, but I would like to have the entire string extracted if it > meets any of the above examples. > > regexp {??\.??} $x output > > What would be the format for matching using regexp? You might find the re_syntax.n manpage useful. -Alex
|
Pages: 1 Prev: Call For Ideas - GSoC/Tcl 2010 Next: ncgi is working with tcl 8.6? |