Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
TCL I want to find a regex pattern to match only integers

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.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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.
about 4 years ago · Juan Pablo Isaza Relatório

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda