Search code examples
regexstringreplacenotepad++

Find a word between double quotes and replace it with suffix using regular expressions in notepad++


I have a file with text as below. I would like to find the word between double quote (i.e., TABLE_NAME_1) and replace that after adding suffix (i.e, _test) to the original word.

Sample data from a file:

<TableName Value="TABLE_NAME_1" />
<TableName Value="TABLE_NAME_22" />
<TableName Value="TABLE_NAME_333" />

Expected data:

<TableName Value="TABLE_NAME_1_test" />
<TableName Value="TABLE_NAME_22_test" />
<TableName Value="TABLE_NAME_333_test" />

I tried like below. But this adds the suffix at the end of the line instead of just before the last double quote.

enter image description here


Solution

  • You can use

    Find What: <TableName Value="[^"]*\K
    Replace with: _test

    Here, <TableName Value="[^"]*\K matches <TableName Value=", then zero or more chars other than " (with [^"]*) and then \K omits the text matched so far. Thus, the _test is added to the empty string just before the trailing ".

    See demo screenshot:

    enter image description here