[英]Keep only the strings in between quotes in Notepad++
In Notepad++, I use the expression (?<=").*(?=")
to find all strings in between quotes. 在Notepad ++中,我使用表达式
(?<=").*(?=")
来查找引号之间的所有字符串。 It would the seem rather trivial to be able to only keep those results. 能够仅保留这些结果似乎相当微不足道。 However, I cannot find an easy solution for this.
但是,我找不到一个简单的解决方案。
I think the problem is that Notepad++ is not able to make multiple selections. 我认为问题是Notepad ++无法进行多项选择。 But there must be some kind of workaround, right?
但必须有某种解决方法,对吧? Perhaps I must invert the regex and then find/replace those results to end up with the strings I want.
也许我必须反转正则表达式,然后找到/替换这些结果以最终得到我想要的字符串。
For example: 例如:
blablabla "Important" blabla
blabla "Again important" blablabla
I want to keep: 我想保留:
Important
Again important
There is no great solution for this and depending on your use case I would recommend writing a quick script that actually uses your first expression and creates a new file with all of the matches (or something like this). 没有很好的解决方案,根据您的使用情况,我建议编写一个实际使用您的第一个表达式的快速脚本,并创建一个包含所有匹配项的新文件(或类似的东西)。 However, if you just want something quick and dirty, this expression should get you started:
但是,如果你只想要快速和肮脏的东西, 这个表达式应该让你开始:
[^"]*(?:"([^"]*)")?
\1\n
Explanation: 说明:
[^"]* # 0+ non-" characters
(?: # Start non-capturing group
" # " literally
( # Start capturing group
[^"]* # 0+ non-" characters
) # End capturing group
" # " literally
)? # End non-capturing group AND make it optional
The reason the optional non-capturing group is used is because the end of your file may very well not have a string in quotes, so this isn't a necessary match (we're more interested in the first [^"]*
that we want to remove). 使用可选的非捕获组的原因是因为文件的末尾很可能没有引号中的字符串,所以这不是必要的匹配(我们对第一个
[^"]*
更感兴趣我们要删除)。
Hard to be certain from your post, but
I think you may want
: SEE BELOW 很难从你的帖子中确定,但
我认为你可能想要
: 见下文
<(?<=")(.*)(?=")
The part you keep will be captured as \\2
. 您保留的部分将被捕获为
\\2
。
(?<=")(.*)(?=")
\1 \2 \3
Your original regex string uses parentheses to group characters for evaluation. 您的原始正则表达式字符串使用括号将字符分组以进行评估。 Parentheses ALSO group characters for capturing.
圆括号ALSO组字符用于捕获。 That is what I added.
这就是我添加的内容。
The regex pattern you provided doesn't seem to work correctly. 您提供的正则表达式模式似乎无法正常工作。 Won't this work?
这不行吗?
\"(.*)\"
\\1
now captures the content. \\1
现在捕获内容。
Try something like this: 尝试这样的事情:
[^"\r\n]+"([^"]+)"[^"\r\n]+
And replace with $1
. 并以
$1
替换。 The above regex assumes there will be only 2 double quotes in each line. 上面的正则表达式假设每行只有2个双引号。
[^"]+
matches non-quote characters. [^"]+
匹配非引号字符。
[^"\\r\\n]+
matches non-quote, non newline characters. [^"\\r\\n]+
匹配非引号,非换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.