如何在 Bigquery 中使用 Regexp_extract 提取第二个括号内的单词?

How to extract the words inside the 2nd brackets using Regexp_extract in Bigquery?

我在 bigquery table 中有一个 textPayload 列包含这些值

textPayload

# User@Host: root[root] @  [44.27.156.25]  thread_id: 67301  server_id: 1220687984

我需要按以下方式将用户名和主机名提取为单独的字段:

用户:root 主机:44.27.156.25,

此列的所有值都将包含上面发布的文本

我正在这样尝试 Select Regexp_Extract(textPayload, -> 无法获取正则表达式

我是 regexp_extract 的新手,我无法提取第二个单词 host:44.27.156.25,

谁能帮我通过 Regexp_extract 提取主机名?

尝试 regexp_extract_allr'\[(.+?)\]':

select regexp_extract_all('# User@Host: root[root] @  [44.27.156.25]  thread_id: 67301  server_id: 1220687984', r'\[(.+?)\]')

您可以在文本有效负载中使用 User@ 的上下文,并且您需要方括号中的 IP 地址,以找到您想要的内容:

SELECT
    textPayload,
    REGEXP_EXTRACT(textPayload, r"\bUser@.*?\[(.*?)\]") AS User,
    REGEXP_EXTRACT(textPayload, r"\[(\d+\.\d+\.\d+\.\d+)\]"
FROM yourTable;