regexp_extract
时间: 2023-09-10 20:10:45 浏览: 46
`regexp_extract` is a function in Apache Spark that allows you to extract substrings from a string based on a regular expression pattern. It takes two arguments: the input string and the regular expression pattern. The output of the function is the first occurrence of the pattern in the input string.
For example, consider the following input string and regular expression pattern:
Input string: "The quick brown fox jumps over the lazy dog"
Regular expression pattern: "brown (\w+) jumps"
The regular expression pattern matches the word "brown" followed by one or more word characters (\w+), followed by the word "jumps". The parentheses around \w+ indicate a capturing group, which means that the matched substring will be extracted.
Using `regexp_extract`, we can extract the substring that matches the regular expression pattern:
```
SELECT regexp_extract("The quick brown fox jumps over the lazy dog", "brown (\\w+) jumps", 1)
```
The output of this query will be: "fox". The third argument of `regexp_extract` specifies which capturing group to extract. In this case, we want to extract the first capturing group, which corresponds to the word "fox".
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)