1
votes

Within the JavaScript UDF I've been writing for BigQuery, I want to use a Regular Expression. Within JavaScript I can use var rep = new RegExp(/require\(\[([^\]]+)\]/, 'gm'); just fine. When run through BigQuery though, it has this error: Error: Syntax error: Illegal escape sequence: \(.

Is there any way to escape these for BigQuery JS UDFs?

Sample query: https://bigquery.cloud.google.com/savedquery/300830567303:6116513b17ca4a77b58fec869fe5a846

1
When you propose simple query - i suggest you to mention cost of such query for those who can accidentally run it and than pay unexpected $$$. your query's cost is - Valid: This query will process 2.21 TB when run. and the cost will be at least $11.00 - if you use BigQuery Mate for example - you will be able to catch this easily - if not - you can miss it - and end up with extra billMikhail Berlyant

1 Answers

3
votes

Yes!

The trick is that you have to escape every backslash as \\ to get a single backslash into your JavaScript UDF. Your regex then has to be:

var re = new RegExp(/require\\((\\[[^\\]]+\\])/, 'gm');