Redshift正则表达式匹配,直到模式匹配但不包括模式

时间:2022-01-01 23:04:51

Since Redshift does not support lookahead assertion, I am in need of a way to find a substring pattern match, however, want to include string up to the pattern match without including the pattern itself.

由于Redshift不支持超前断言,我需要一种方法来查找子串模式匹配,但是,想要包含字符串直到模式匹配而不包括模式本身。

Yes, as an alternative, I could of course use substring(), however, if there is no substring match, I would still like the full string returned. This approach would require use of sever case statements and would not be suitable.

是的,作为替代方案,我当然可以使用substring(),但是,如果没有子串匹配,我仍然希望返回完整的字符串。这种方法需要使用严格的案例陈述,并不适合。

Using a regular expression would be ideal - for example:

使用正则表达式是理想的 - 例如:

The quick brown fox jumped over the lazy dog
Match String: jumped
Desired output would be:  The quick brown fox

1 个解决方案

#1


0  

If you have a fixed string -- and really don't need regular expressions -- just use split_part():

如果你有一个固定的字符串 - 并且真的不需要正则表达式 - 只需使用split_part():

select split_part('the quick brown fox jumps', 'jump', 1)

#1


0  

If you have a fixed string -- and really don't need regular expressions -- just use split_part():

如果你有一个固定的字符串 - 并且真的不需要正则表达式 - 只需使用split_part():

select split_part('the quick brown fox jumps', 'jump', 1)