Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

381
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!