问题描述
.*是零个或多个次数的任何字符.我试图找到以元音开头的单词,我用过
.* is any character zero or more number of times. I was trying to find words starting with vowel and i used
^[aeiou](*)
它给了我所有以元音开头的单词.当我执行^[aeiou].*
时,给出相同的结果现在我正在寻找以元音结尾的单词.我做到了
And it gave me all words starting with vowel. Same result is given when i do ^[aeiou].*
Now i was looking for words that end with vowels. I did
^(*)[aeiou]$
它没有给出结果,但是当我执行^.*[aeiou]$
时它给出了有效的结果.请解释两者含义上的差异.谢谢
It gave no result but when i did ^.*[aeiou]$
it gave valid results. Please explain the difference in the meaning of both. Thanks
推荐答案
看来,在Oracle 11中,*
和+
模式(之前没有任何内容)会生成零宽度的匹配项.因此(*)
和(+)
捕获的组()
分别包含零宽度模式*
或+
.
It appears that, in Oracle 11, the *
and +
patterns (with nothing preceding them) generate zero-width matches. So (*)
and (+)
are capturing groups ()
containing the zero-width patterns *
or +
respectively.
所有这些查询都返回一行:
All these queries return a row:
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '*' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '(*)' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '^*' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '^(*)' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '*1' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '+' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '(+)' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '^+' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '^(+)' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '+1' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '^+1' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '+1$' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '^+1$' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '()' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '12', '1(*)2' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '12', '1(+)2' );
这些查询不返回任何行:
These queries do not return any rows:
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '*2' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '^*$' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', '^+$' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '12', '11(*)2' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '12', '11(+)2' );
此外,将任何模式与NULL
匹配或将字符串与NULL
模式匹配都不会返回任何行:
Also, matching any pattern against NULL
or a string against a NULL
pattern will not return any rows:
SELECT * FROM DUAL WHERE REGEXP_LIKE( NULL, '*' );
SELECT * FROM DUAL WHERE REGEXP_LIKE( '1', NULL );
使用REGEXP_SUBSTR
:
SELECT REGEXP_SUBSTR( '1', '+' ) FROM DUAL;
输出包含NULL
的单行.
这篇关于regexp中的(*)和.*有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!