I am using
(?<![\d.])[0-9]+(?![\d.])
This does the job for me but I can't use it as it says "couldn't compile regular expression pattern: quantifier operand invalid while executing"
I'm looking for any equivalents.
Tcl regex does not support lookbehinds, although it supports lookaheads.
You can use something like
set data {12 3.45 1.665 345}
set RE {(?:^|[^0-9.])(\d+)(?!\.?\d)}
set matches [regexp -all -inline -- $RE $data]
foreach {- group1} $matches {
puts "$group1"
}
Output:
12
345
See the online demo. The (?:^|[^0-9.])(\d+)(?!\.?\d) regex matches
(?:^|[^0-9.]) - start of string or a char other than a digit and a dot(\d+) - Group 1: one or more digits(?!\.?\d) - a negative lookahead that fails the match if there is an optional . and then a digit immediately to the right of the current location.If the integers are individual words and not framed by other characters, you don't need a regular expression to get just them and prune out the non-ints:
% set data {12 3.45 1.665 345}
12 3.45 1.665 345
% set ints [lmap w $data { if {[string is integer $w]} { set w } else { continue } }]
12 345
or just string is integer $whatever if you want to check to see if a variable contains just an integer. There's also wideint for 64-bit integers and entier for bigints.