亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

正則表達式 - 每組行一個組

正則表達式 - 每組行一個組

慕勒3428872 2023-05-17 14:50:18
假設我有一個文本文件,其內容類似于以下內容:021 Line one of section A.021 Line two of Section A.021 Line three of section A.021 Part two of Line three of Section A.021 We just skipped line four, but that's okay.021 Back to line six.Non-formatted lines to be ignored. This can be from 0 lines, to any number of lines, and the content can be any text.033 Line 1 of Section B033 Line 2 of Section B033 Okay, that's enough.是否可以在正則表達式中給我兩組,第一組包含所有以開頭的行021,第二組包含所有以開頭的行033?行標記會有所不同,但始終是\d{3}.
查看完整描述

1 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

您可能會在捕獲組的開頭捕獲數字,并\1在重復時使用對該組的反向引用。

這將為您提供開頭數字相同的匹配項。

^(\d{3}) .*(?:\r?\n\1.*)*

正則表達式演示


查看完整回答
反對 回復 2023-05-17
  • 1 回答
  • 0 關注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號