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

268
Views
BigQuery usando Regex en Javascript UDF escapando valor dinámico

Estoy tratando de usar expresiones regulares con variable dinámica en BigQuety con JS UDF, pero hay un problema con el escape y no sé cómo resolverlo.

 CREATE TEMP FUNCTION `replaceRegex`(org STRING, to_replace STRING, replace_to STRING) RETURNS STRING LANGUAGE js AS """ re_string = `\\b${to_replace}\\b` let re = new RegExp(re_string, 'gi'); return org.replace(re, replace_to); """; SELECT replaceRegex('The quick brown fox jumps over the lazy dog', 'fox', 'bear')

Esta versión no funciona.

Pero cambio: \\b${to_replace}\\b a:

 re_string = /\\bfox\\b/

Entonces funciona.

Pero no puedo codificar mi expresión regular, tiene que pasar un valor dinámico.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Agregar r al comienzo de su cadena entre comillas triples hace que su código funcione, ya que trata todo como cadenas sin procesar. Consulte esta referencia . Su código debe ser:

 CREATE TEMP FUNCTION `replaceRegex`(org STRING, to_replace STRING, replace_to STRING) RETURNS STRING LANGUAGE js AS r""" re_string = `\\b${to_replace}\\b` let re = new RegExp(re_string, 'gi'); return org.replace(re, replace_to); """; SELECT replaceRegex('The quick brown fox jumps over the lazy dog', 'fox', 'bear')

Prueba:

ingrese la descripción de la imagen aquí

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!