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

351
Visualizações
Regular expression [Any number]

I need to test for "[any number]" in a string in javascript. how would i match it?

Oh, "[" and "]" also need to be matched.

so string like "[1]" or "[12345]" is a match.

Non match: "[23432" or "1]"

So for example:

$('.form .section .parent').find('input.text').each(function(index){
      $(this).attr("name", $(this).attr("name").replace("[current]", "['"+index+"']"));
});

I need to replace input fields name: "items[0].firstname" to "items[1].firstname" thanks

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

UPDATE: for your updated question

variable.match(/\[[0-9]+\]/);

Try this:

variable.match(/[0-9]+/);    // for unsigned integers
variable.match(/[-0-9]+/);   // for signed integers
variable.match(/[-.0-9]+/);  // for signed float numbers

Hope this helps!

over 4 years ago · Santiago Trujillo Relatório

0

if("123".search(/^\d+$/) >= 0){
   // its a number
}
over 4 years ago · Santiago Trujillo Relatório

0

I always use the following regular expression to detect any kind of number in a string. Had no issues so far.

'(([\+\-]*\d*\.*\d+[eE])?([\+\-]*\d*\.*\d+))'

In detail:

'([\+\-]*\d*\.*\d+)'

to match a (non-)decimal number with(out) leading digits or sign

'([\+\-]*\d*\.*\d+[eE])?'

to match an exponential base before the number.

If there are brackets around required, you can add them inside or outside of the surrounding paranthesis:

'(\[([\+\-]*\d*\.*\d+[eE])?([\+\-]*\d*\.*\d+)\])'

In fact the surrounding paranthesis are not necessary, but i keep them to easier concatenate the expression with others.

over 4 years ago · Santiago Trujillo 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