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

253
Views
¿Qué tiene de malo esta expresión regular para eliminar la subcadena?

Intentando eliminar el destinatario adicional de una cadena de dirección. En el ejemplo a continuación, dba bobs es la cadena de destino para eliminar.

 const NOT_EXTRA_ADDRESSEE = /^(?!.*(attn|co|dba|fka|dept).*\n).*\n/gim; "bobs burgers dba bobs dinner\n100 Oceanside drive\nnashville, tn 37204" .replace(NOT_EXTRA_ADDRESSEE, "");

Lo anterior produce:

 bobs burgers dba bobs dinner 100 oceanside drive nashville tn 37204

Cuando lo deseado es:

 bobs burgers 100 oceanside drive nashville tn 37204

¿Qué estoy haciendo mal? A veces, la entrada tiene un '\n' antes del 'dba'.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede simplificar su expresión regular a: /\b(attn|co|dba|fka|dept)\b.*/gm

Prueba aquí: https://regex101.com/r/TOH9VV/2

 const regex = /\b(attn|co|dba|fka|dept)\b.*/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('\\b(attn|co|dba|fka|dept)\\b.*', 'gm') const str = `bobs burgers dba bobs 100 Oceanside drive nashville, tn 37204 bobs burgers dba bobs 100 attn Oceanside drive nashville, tn 37204 bobs burgers dba bobs 100 Oceanside depth drive nashville, tn fka 37204`; const subst = ``; // The substituted value will be contained in the result variable const result = str.replace(regex, subst); console.log('Substitution result: ', result);

EDITAR: Sugerencia incluida del usuario Cary Swoveland en los comentarios.

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!