错误:大查询REGEX_EXTRACT无法解析正则表达式:无效的perl运算符:(?<

时间:2018-11-01 09:06:51

标签: regex google-bigquery

我试图从BigQuery的#1中提取#2

REGEXP_EXTRACT(",\"AQk8tmAg94ZUZwqYKd6kHrswiVZR0wKNuTvSpr6COCLpki\"", r"(?<=,\")[a-zA-Z0-9]*")

#1我要从中提取的字符串

,"AQk8tmAg94ZUZwqYKd6kHrswiVZR0wKNuTvSpr6COCLpki"

#2 REGEX_EXTRACT的预期结果

AQk8tmAg94ZUZwqYKd6kHrswiVZR0wKNuTvSpr6COCLpki

有人可以在正则表达式中帮助我,以正确地排除引号和方括号以从#1中提取#2吗?

2 个答案:

答案 0 :(得分:1)

我怀疑该错误与您向后看有关,<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <form> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email"> <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </form> </div> </div> </div> 不支持。一种解决方法是将REGEX_EXTRACT与捕获组一起使用:

REGEX_REPLACE

在这里,我假设REGEXP_REPLACE(col, r",\"([a-zA-Z0-9]*)\"", "\\1") 的值应为:

col
您在问题中提到的

答案 1 :(得分:1)

以下示例适用于BigQuery标准SQL

#standardSQL
WITH `project.dataset.table` AS (
  SELECT ",\"AQk8tmAg94ZUZwqYKd6kHrswiVZR0wKNuTvSpr6COCLpki\"" string1
)
SELECT REGEXP_EXTRACT(string1, r'([a-zA-Z0-9]+)') string2
FROM `project.dataset.table`

有结果

Row string2  
1   AQk8tmAg94ZUZwqYKd6kHrswiVZR0wKNuTvSpr6COCLpki     

或者只是

SELECT REGEXP_EXTRACT(",\"AQk8tmAg94ZUZwqYKd6kHrswiVZR0wKNuTvSpr6COCLpki\"", r'([a-zA-Z0-9]+)')

请注意,BigQuery使用re2库提供了正则表达式支持-其中不支持(?<=re)。同时,从您的示例中并不清楚为什么您会需要它,就像上面的示例在没有它的情况下所做的工作

同时,如果您正在寻找最接近的正则表达式(有问题),则可以使用r'(?:,\")([a-zA-Z0-9]*)',如下面的示例

SELECT REGEXP_EXTRACT(",\"AQk8tmAg94ZUZwqYKd6kHrswiVZR0wKNuTvSpr6COCLpki\"", r'(?:,\")([a-zA-Z0-9]*)')