Search code examples
regexnotepad++

Select capture-group (mark) in notepad++


I have a pretty simple xml like this:

<myNode EMail="foo@bar.de">
<myNode EMail="alpha@beta.com">

I want to select only the content of Email with the mark-option in the search window.

enter image description here

As you can see, I'm able to select the whole string, but not just the content. I want to extra the raw value of the EMail-attribute. My current way of using this (+ clicking copy marked) and then run search&replace to get rid off the " doesn't seem to be that good.

Following similar questions on SO, I guess it should be doable with something like /1 in the end, but that didn't do the trick. I tried using it like email="(.*?)"/1 but without success. Am I missing something?

In addition, I don't need search & replace, i simply want the content of the email node selected.


Solution

  • You can use

    \bEMail="\K[^\s"@]+@[^\s"@]+(?=")
    

    The pattern matches:

    • \bEMail=" Match literally preceded by a word boundary
    • \K Forget what is matched so far
    • [^\s"@]+@[^\s"@]+ Match a non whitespace string excluding double quotes containing one @ sign
    • (?=") Assert a double quote to the right

    Regex demo

    Or a shorter version if the format is always the same:

    \bEMail="\K[^\s"]+(?=")
    

    enter image description here