2012-05-10 71 views
2

那麼,下一個正則表達式究竟意味着什麼呢?這個正則表達式是什麼意思?

str_([^_]*)(_[_0-9a-z]*)? 

而且是等於^str_[^_]*(_[_0-9a-z]*)?

+1

看看[this](http://www.roblocher.com/technotes/regexp.aspx),可能對您有用。 –

回答

5

str_這些字符字面

([^_]*) 0倍或更多倍的是不是一個下劃線

(_[_0-9a-z]*)?匹配另一個下劃線,然後0個或多個字符的​​匹配任何字符匹配。最後一部分是可選的。

I wrote recently a really brief regex introduction, hope it will help you.

+0

所以,讓我們說'str_MOTH_clone'應該匹配正則表達式,對吧? –

+0

是的,[在Regexr上查看](http://regexr.com?30tg5) – stema

0

str_([^_]*)(_[_0-9a-z]*)?

所以,讓我們來談談對正則表達式:

1)([^_]*) - 抓()任何數(零是可能的)*符號[],不屬於^這個符號_

2)(_[_0-9a-z]*)? - 生存還是毀滅?和捕捉()序列開頭符號_和序列的尾部,其中出現在任何計數*從設置[]_a,b,c,..,z0,1,..9

4

任何符號如所提到的在評論我的回答,http://gskinner.com/RegExr/解釋一下如果你把它放在正則表達式的一切。

str_([^_]*)(_[_0-9a-z]*)? 
\ /^\ /^^^^\  /^^^ 
\/ | \/ |||| \ /||| 
| | | |||| \ /||`- Previous group is optional 
| | | |||| \/ |`-- End second capture group (an underscore and any amount of characters _, 0-9 or a-z) 
| | | |||| | `--- Match any amount (0-infinite) of previous (any character _, 0-9 or a-z) 
| | | |||| `-------- Match any of the characters inside brackets 
| | | ||||    (0-9 means any number between 0 and 9, a-z means any lower case char between a and z) 
| | | |||`------------- Match "_" literally 
| | | ||`-------------- Start second capture group 
| | | |`--------------- End first capture group (any amount of any character which is not underscore) 
| | | `---------------- Match any amount (0-infinite) of previous (any character which is not underscore) 
| | `-------------------^at the start inside [] means match any character not after^
| |      (In this case, match any which is not underscore) 
| `--------------------- Start first capture group 
`------------------------ Match "str_" literally 

的在^str_[^_]*(_[_0-9a-z]*)?開頭的只是意味着它只能匹配你輸入的任何行的開頭。

+0

哇。這是由工具生成的,還是您實際輸入的? –

+0

@ li-aung-yip:輸入它,但我想這是一個好主意。感謝這個想法。 :D – ohaal

+1

Upvote純粹的球和努力。但是,下次使用regexr。 ;) –

相關問題