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

133
Views
Regex para hacer coincidir una cadena solo dentro de otra cadena

Supongamos que aquí hay un texto de muestra:

 Hello this is testing _testisgood _test test ilovetesting again test

la expresión regular

 /test/gi

Da toda la test , pero solo quiero la cadena de test que está rodeada por algún otro carácter, excepto que el espacio significa lo contrario de la coincidencia exacta. En otras palabras, la test en testing , _testisgood , ilovetesting quiero que coincida.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

La respuesta de Bill es buena, pero puede que le guste esta: simplemente encuentre todas las palabras con prueba y luego filtre las inútiles;

 const s = "Hello this is testing _testisgood _test test ilovetesting again test" console.log( (s.match(/[^\s]*test[^\s]*/gi) || []).filter(s => s !== 'test') )
about 4 years ago · Santiago Trujillo Report

0

La expresión regular a continuación coincidirá con 'test' cuando tenga un prefijo de carácter que no sea un espacio en blanco o una corrección posterior.

/([^\s]+test[^\s]*|[^\s]*test[^\s]+)/gi;

O

/(\S+test\S*|\S*test\S+)/gi;

 const sentence = "Hello this is testing _testisgood _test test ilovetesting again test"; regex = /([^\s]+test[^\s]*|[^\s]*test[^\s]+)/gi; console.log(sentence.match(regex));

about 4 years ago · Santiago Trujillo Report

0

Puede hacer coincidir solo _testisgood e ilovetesting en su ejemplo especificando uno o más caracteres que no sean espacios en blanco antes y después de test , así:

/[^\s]+test[^\s]+/gi

Si también desea hacer coincidir testing , suelte [^\s]+ desde el principio del patrón.

about 4 years ago · Santiago Trujillo 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!