Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 在PostgreSQL中使用正则表达式提取字符串的部分_Regex_Postgresql - Fatal编程技术网

Regex 在PostgreSQL中使用正则表达式提取字符串的部分

Regex 在PostgreSQL中使用正则表达式提取字符串的部分,regex,postgresql,Regex,Postgresql,我想提取第一个\u名称和第二个\u名称字符串,但使用此正则表达式只能获取第一个\u名称字符串 选择 子串( 'a:2:{i:0;s:14:“第一个名字”;i:1;s:15:“第二个名字”}, '\"[^\"]*\" ' )作为obs_regex 如何修改我的正则表达式以获得结果first\u name second\u name 感谢您您可以使用g标志匹配多个事件,并且您需要使用捕获组来获取没有量化标记的值: SELECT REGEXP_MATCHES ( 'a:2:{i:0

我想提取
第一个\u名称
第二个\u名称
字符串,但使用此正则表达式只能获取
第一个\u名称
字符串

选择
子串(
'a:2:{i:0;s:14:“第一个名字”;i:1;s:15:“第二个名字”},
'\"[^\"]*\" '
)作为obs_regex
如何修改我的正则表达式以获得结果
first\u name second\u name


感谢您

您可以使用
g
标志匹配多个事件,并且您需要使用捕获组来获取没有量化标记的值:

SELECT
   REGEXP_MATCHES (
      'a:2:{i:0;s:14:"first_name";i:1;s:15:"second_name";}',
      '"([^"]*)"', 'g'
   ) as obs_regex
结果:

要获得连接的匹配字符串,您需要将
regexp\u匹配
结果“转换”为数组,并使用
array\u转换为字符串

SELECT ARRAY_TO_STRING (
 ARRAY (
   SELECT REGEXP_MATCHES (
      'a:2:{i:0;s:14:"first_name";i:1;s:15:"second_name";}',
      '"([^"]*)"', 'g'
   )
 ), ' ') as obs_regex
结果:


我会使用
split\u part()
因为这样,我的解决方案对您有用吗?