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

164
Visualizações
Javascript Regex to find a word started with or followed by anything other than a character or digit

I'm trying to find names of programming languages in text, I've tried for days to find the correct regex, but I can't find it. Also running into problems when the language is C++ or C# I want to match the name of the languages if it starts with or ends with anything other than letters or digits.

  reg = new RegExp("\\b[\\+" + language[element] + "] \\b", "gi");
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use

new RegExp("(?<!\\w)" + language[element].replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + "(?!\\w|\\+{2}|#)", "gi");

See the regex demo if language[element] holds the C text. Details:

  • (?<!\w) - no word char allowed immediately before the current location
  • C - a C char
  • (?!\w|\+\+|#) - a negative lookahead that fails the match if there is a word char, or ++ or a # char immediately to the right of the current location.
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