正则表达式给出所有字母
Regex expression Giving all letters
我需要一个字符串中所有 4 个大写字母组。
所以我正在使用 REGEXP_REPLACE([Description],'\b(?![A-Z]{4}\b)\w+\b',' ')
in Tableau
替换所有小写字母和多余字符。我只想获取字符串长度为 4 的大写字母实例。
通过 google 我知道我不能使用 Regex_extract(因为不支持 /g)
我的字符串:
"The following trials have no study data-available, in the RBM mart. It appears as is this because they were . In y HIWEThe trials currently missing data are:
JADA, JPBD, JVCS, JADQ, JVDI, JVDO, JVTZ"
我写了[^A-Z]{4}/g
。
我要:
HIWE JADA JPBD JVCS JADQ JVDI JVDO JVTZ
但这也给了我一个大写字母和 space 包括在内。
谢谢
您可以使用 this regex:
((?<=[A-Z]{4})|^).*?(?=[A-Z]{4}|$)
解释:
( # one of:
^ # the starting position
| # or
(?<=[A-Z]{4}) # any position after four upper letters
) #
.*? # match anything till the first:
(?= # position which in front
[A-Z]{4} # has four upper letters
| # or
$ # is the string's end
) #
如有任何疑问,请随时提问:)
我需要一个字符串中所有 4 个大写字母组。
所以我正在使用 REGEXP_REPLACE([Description],'\b(?![A-Z]{4}\b)\w+\b',' ')
in Tableau
替换所有小写字母和多余字符。我只想获取字符串长度为 4 的大写字母实例。
通过 google 我知道我不能使用 Regex_extract(因为不支持 /g)
我的字符串:
"The following trials have no study data-available, in the RBM mart. It appears as is this because they were . In y HIWEThe trials currently missing data are:
JADA, JPBD, JVCS, JADQ, JVDI, JVDO, JVTZ"
我写了[^A-Z]{4}/g
。
我要:
HIWE JADA JPBD JVCS JADQ JVDI JVDO JVTZ
但这也给了我一个大写字母和 space 包括在内。
谢谢
您可以使用 this regex:
((?<=[A-Z]{4})|^).*?(?=[A-Z]{4}|$)
解释:
( # one of:
^ # the starting position
| # or
(?<=[A-Z]{4}) # any position after four upper letters
) #
.*? # match anything till the first:
(?= # position which in front
[A-Z]{4} # has four upper letters
| # or
$ # is the string's end
) #
如有任何疑问,请随时提问:)