我有一個巨大的文本文件(200k行)。 我使用Notepad ++,我需要它返回這個詞在特定字符串(「string1」)和第一個出現的另一個(「」)之間的行。例如,我在尋找這個詞在「myWord」和文本文件看起來像這樣:使用正則表達式來搜索一個確切的字符串和第一個出現的另一個確切的字符串之間的特定字
"string1" "string 2 with myword in it" "string 3 also with myword in it" "string 4 random stuff"
"string1" "string 2 random stuff" "string 3 also with myword in it" "string 4 random stuff"
"string1" "string 2 with myword in it" "string 3 random stuff" "string 4 random stuff"
搜索的結果應該返回1號線和3,而不是2行 因此,我認爲它像這樣的:
(?<="string1" ")(.*)(\bmyword\b)(.*)(?=")
不過這也返回2號線,因爲myword是字符串3
我是當它涉及到正則表達式一個小白,這是我第一次使用它......
請幫助容易我的痛苦:)
嘗試'(?<= 「字符串1」 「)((?:(?」 \ H + 「)。)*)\ bmyword \ B([^」] *)' –
哎,這似乎工作!謝謝一堆。 –