Kman
Kman

Reputation: 5001

Regex (Notepad++) to search and replace content

I'm not too familiar with the Notepad++ regex option for search and replace, and in need for a little help.

Parsing from one sql syntax to another, I would like to do the following. For all lines with the "pattern" ADD FOREIGN KEY "**********" ("**"), I would like to insert som text at section 3 (where the whitespace is)

From

   (      1       )(          2         )(3)(4)
   ADD FOREIGN KEY "FK_MY_ACCOUNT_PROJECT" ("id")

to

   ADD FOREIGN KEY "FK_MY_ACCOUNT_PROJECT" [new text] ("id")

Upvotes: 1

Views: 88

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520978

Try this find and replace in regex mode:

Find:

(ADD FOREIGN KEY "[^"]+" )(\("[^"]+"\))

Replace:

$1[new text] $2

Here is a demo showing that the two groups in fact are getting matched correctly.

Demo

Upvotes: 2

wizzwizz4
wizzwizz4

Reputation: 6426

Sounds like a job for... Regular Expressions! Na na na na na n--

Oh, wait... You already knew that... :-/

Anyway... In the "replace" box you can use \6 to refer to a numbered group, so if you have a regex like this:

(ADD FOREIGN KEY) "([^\\]*)" \("([^\\]*)"\)

you can replace with this:

\1 "\2" insertion ("\3")

Upvotes: 1

Related Questions