Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

392
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda