Question

In Notepad++, I use the expression (?<=").*(?=") to find all strings in between quotes. 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. 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
Was it helpful?

Solution

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).

OTHER TIPS

Try something like this:

[^"\r\n]+"([^"]+)"[^"\r\n]+

And replace with $1. The above regex assumes there will be only 2 double quotes in each line.

[^"]+ matches non-quote characters.

[^"\r\n]+ matches non-quote, non newline characters.

regex101 demo

Hard to be certain from your post, but I think you may want : SEE BELOW

<(?<=")(.*)(?=") 

The part you keep will be captured as \2.

(?<=")(.*)(?=")
  \1   \2  \3

Your original regex string uses parentheses to group characters for evaluation. Parentheses ALSO group characters for capturing. That is what I added.

Update:

The regex pattern you provided doesn't seem to work correctly. Won't this work?

\"(.*)\"

\1 now captures the content.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top