Using regular expressions to do mass replace in Notepad++ and Vim

前端 未结 16 1545
迷失自我
迷失自我 2020-12-08 04:25

So I\'ve got a big text file which looks like the following:

相关标签:
16条回答
  • 2020-12-08 05:04

    There are two problems with your original solution. Firstly, your example text:

    <option value value='1' >A
    

    has two occurences of the "value" word. Your regex does not. Also, you need to escape the opening brace in the quantifier of your regex or Vim will interpret it as a literal brace. This regex works:

    :%s/<option value value='.\{1,}' >//g
    
    0 讨论(0)
  • 2020-12-08 05:05

    There is a very simple solution to this unless I have not understood the problem. The following regular expression:

    (.*)(>)(.*)
    

    will match the pattern specified in your post.

    So, in notepad++ you find (.*)(>)(.*) and replace it with \3.

    The regular expressions are basically greedy in the sense that if you specify (.*) it will match the whole line and what you want to do is break it down somehow so that you can extract the string you want to keep. Here, I have done exactly the same and it works fine in Notepad++ and Editplus3.

    0 讨论(0)
  • 2020-12-08 05:06

    Here's a nice article on Notepad++ Regular expressions
    http://markantoniou.blogspot.com/2008/06/notepad-how-to-use-regular-expressions.html

    0 讨论(0)
  • 2020-12-08 05:10

    Notepad ++ : Search Mode = Regular expression

    Find what: (.*>)(.)

    Replace with: \2

    0 讨论(0)
  • 2020-12-08 05:10

    Very simple just Find:

    <option value value=.*?>
    

    and Click Replace

    0 讨论(0)
  • 2020-12-08 05:11

    This will work. Tested it in my vim. the single quotes are the trouble.

    1,$s/^<option value value=['].['] >/
    
    0 讨论(0)
提交回复
热议问题