简体   繁体   English

记事本中的正则表达式两个单词搜索++

[英]regex two words search in Notepad++

I want to in below sample text using regex find: 我想在下面的示例文本中使用正则表达式查找:

  • The lines having keyword "Loves" and ends with " 关键字为“ Loves”且以“
  • Append " Very Much" only to those lines which satisfy the above. 仅将“非常多”追加到满足上述条件的那些行。

I have tried searching for: 我尝试搜索:

Loves*."$

And replace with /1 Very Much but no luck, pointers are appreciated. 并替换为/1 Very Much好,但是没有运气,我们对指针表示赞赏。

I am using Notepad++ for this. 我为此使用Notepad ++。

"Sample Text"
--------------------

    DOLLY Loves DOLLS" Like Elephant"
    DOLLY;
    DOLLY Loves DOLLS Like Dog"
    DOLLY Loves DOLLS Like Cat" But Bats Not
    DOLLY "Loves" Her Lover Matt"
    Mr. O' Neil" King Hates Dolls
    DOLLY Loves DOLLS Like Bat"
    DOLLY;

You can use the following regular expression in Notepad++. 您可以在Notepad ++中使用以下正则表达式。

Find: \b(Loves.*")$
Replace: \1 Very Much

Note: Make sure "Regular expression" is checked and . 注意:确保选中“正则表达式”,然后单击 . matches newline is unchecked. 匹配换行符未选中。

This is untested but should work. 这未经测试,但应该可以。 Make sure case-insensitive matching is on. 确保不区分大小写的匹配已打开。 Search: 搜索:

(Loves.*")$

Replace 更换

$1 Very Much

Also, make sure you're doing a global replace (Replace All). 另外,请确保您要进行全局替换(全部替换)。 Otherwise, it will only match the first instance after the cursor. 否则,它将仅与光标之后的第一个实例匹配。 See this Regex101 demo 观看此Regex101演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM