如何通过正则表达式匹配/查找字符串

时间:2022-02-06 19:23:35

Here is my regular expression:

这是我的正则表达式:

(?is)(\b\w+\b)(?:,\s*'[^']*',\s*'[^']*'\))?\s*\bas\b\s*\bdisplay_text\b

Currently its just matching field2 from the following strings.

目前它只是匹配来自以下字符串的field2。

  1. SELECT DISTINCT field1 AS value, field2 AS display_text
  2. SELECT DISTINCT field1 AS值,field2 AS display_text
  3. SELECT DISTINCT replace(field1, ',', '/') AS value, replace(field2, ',', '/') AS display_text
  4. SELECT DISTINCT替换(field1,',','/')AS值,替换(field2,',','/')AS display_text

I need a regular expression that can match field2 from 1st statement and replace(field2, ',', '/') from 2nd statement.

我需要一个能够匹配第一个语句中的field2的正则表达式,并从第二个语句中替换(field2,',','/')。

Please anyone help me to create this regular expression.

请任何人帮我创建这个正则表达式。

1 个解决方案

#1


1  

Just add an optional pattern to match the beginning replace( string.

只需添加一个可选模式以匹配开头替换(字符串。

(?is)\b(?:\S+\()?\b\w+\b(?:,\s*'[^']*',\s*'[^']*'\))?(?=\s*\bas\b\s*\bdisplay_text\b)

DEMO

DEMO

#1


1  

Just add an optional pattern to match the beginning replace( string.

只需添加一个可选模式以匹配开头替换(字符串。

(?is)\b(?:\S+\()?\b\w+\b(?:,\s*'[^']*',\s*'[^']*'\))?(?=\s*\bas\b\s*\bdisplay_text\b)

DEMO

DEMO