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

389
Visualizações
Regex (node js) works on linux but not on window 10

I get the object message via http protocol. This object has the body property.

message.body: 'Denversaurus $24.90' +
    'Bread with sesame, artisan meat, cheddar, Jurassic sauce, mustard and honey, lettuce, tomato and pickles.'

I apply the following regex to that variable:

const regex = new RegExp(/([\w\dà-ú'" ]+)R\$ ([\d+,\.]+)[\n\r]([ \w\dà-ú'"\.,\+\*\(\)]+)/)
const arrayMatch = regex.exec(message.body)

On linux, I get the expected result, but on windows, the arrayMatch variable returns with the value null. And I can't solve it. Does anyone have the solution?

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

0

your regex is incorrect . please test all patterns first with online tools like : https://debuggex.com

As for this, I have to make it clear to you that all APIs implemented by Node Js are multiplatform unless the command is specific to a particular operating system. But in the case of regex, it is supported by all operating systems.

Also, when you want to build a regex with a constructor, its argument must be a string.

let regex1 = /(\w+)/gi;
//or
let regex2 = new RegExp("(\\w+)", "gi")
about 4 years ago · Juan Pablo Isaza Relatório

0

They must only differ in line ends: "\n" is Linux-style and "\r\n" is Windows-style.

Use

const regex = new RegExp(/([\wà-ú'" ]+)R\$ ([\d+,\.]+)[\n\r]+([ \wà-ú'"\.,\+\*\(\)]+)/)

EXPLANATION

--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    [\wà-ú'" ]+              any character of: word characters (a-z,
                             A-Z, 0-9, _), 'à' to 'ú', ''', '"', ' '
                             (1 or more times (matching the most
                             amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  R                        'R'
--------------------------------------------------------------------------------
  \$                       '$'
--------------------------------------------------------------------------------
                           ' '
--------------------------------------------------------------------------------
  (                        group and capture to \2:
--------------------------------------------------------------------------------
    [\d+,\.]+                any character of: digits (0-9), '+',
                             ',', '\.' (1 or more times (matching the
                             most amount possible))
--------------------------------------------------------------------------------
  )                        end of \2
--------------------------------------------------------------------------------
  [\n\r]+                  any character of: '\n' (newline), '\r'
                           (carriage return) (1 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  (                        group and capture to \3:
--------------------------------------------------------------------------------
    [ \wà-                    any character of: ' ', word characters
    ú'"\.,\+\*\(\)]+         (a-z, A-Z, 0-9, _), 'à' to 'ú', ''',
                             '"', '\.', ',', '\+', '\*', '\(', '\)'
                             (1 or more times (matching the most
                             amount possible))
--------------------------------------------------------------------------------
  )                        end of \3
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