You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hive如何用regexp_extract函数提取三重引号内的字符串

Extract Text Inside Triple Quotes Using Hive's regexp_extract

To get just the text inside the triple quotes (without including the quotes themselves), you need to adjust your regex to capture the inner content using a capturing group and reference that group instead of the full match.

Corrected Query

For your first example, the working query would be:

select '"""hello:world"""' as in_str, 
       regexp_extract('"""hello:world"""', '"""(.*?)"""', 1) as out_str;

This will return hello:world as the output.

How It Works

Let’s break down the regex pattern """(.*?)""":

  • """: Matches the opening triple quotes exactly.
  • (.*?): A capturing group that matches any character (.) zero or more times, but in a non-greedy way (?). This ensures we stop at the first occurrence of closing triple quotes instead of over-matching (critical if your data ever has multiple quote pairs in a single string).
  • """: Matches the closing triple quotes exactly.
  • The third argument 1 tells regexp_extract to return the content of the first capturing group, not the entire matched string (which would be group 0 and include the quotes).

Testing with Your Second Example

For the string """abc:|:def""", the same pattern works perfectly:

select '"""abc:|:def"""' as in_str, 
       regexp_extract('"""abc:|:def"""', '"""(.*?)"""', 1) as out_str;

Output: abc:|:def

Quick Tip

If you’re working with a table column instead of a literal string, just replace the literal with your column name:

select your_column as in_str,
       regexp_extract(your_column, '"""(.*?)"""', 1) as out_str
from your_hive_table;

内容的提问来源于stack exchange,提问作者Regressor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:41:34