Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
regular expression 的問題
我想用regular expression過濾一些郵件
這些郵件的來源特色都是@後面加上重複兩次的英文名字,再加上.net
例如:
@cathycathy.net
@edithedith.net
@alinaalina.net
@carrycarry.net
等等...
請問要怎麼用regular expression來表達這上述的這些字串呢?
我的寫法是 '@[\w+]{2}\.net$',不過不行
請問正確的寫法是什麼,以及我的寫法錯在哪裡.?
初學者,請多包含 <(_ _)>
2 Answers
- JayLv 52 decades agoFavorite Answer
@(\w+){2}\.net$
應該是用括號 而不是用 四方括號
四方括號 是指其中的某一個
下面龍大大 講的是對的
@(\w+)\1\.net$
我測試的結果 她才是正確的
不過 我不確定 \1 是什麼意思
- 龍Lv 72 decades ago
這也行
egrep "@(\w+)\1\.net$" text
2005-06-24 05:39:42 補充:
是"back-reference"
2005-06-24 05:46:13 補充:
是"back-reference", 1表示第一個().
像egrep "@(\w+)(\w+)\1\1\2\1\.net$" text
會只會顯示@alinaalina.net.
因第1個(\w+)代表a,第2個(\w+)代表lin. 所以alinaalina變成
a lin a a lin a
1 2 1 1 2 1