Reputation: 6590
I want to remove text between two strings using regular expression
in notepad++. Here is my full string
[insertedOn]) VALUES (1, N'1F9ACCD2-3B60-49CF-830B-42B4C99F6072',
I want final string like this
[insertedOn]) VALUES (N'1F9ACCD2-3B60-49CF-830B-42B4C99F6072',
Here I removed 1, from string. 1,2,3 is in incremental order.
I tried lot of expression but not worked. Here is one of them (VALUES ()(?s)(.*)(, N')
How can I remove this?
Upvotes: 2
Views: 5665
Reputation: 48711
You should first escape literal (
before VALUES
: \(
By doing so, .*
in your regex in addition to s
(DOTALL) flag causes engine to greedily match up to end of input string then backtracks to stop at the first occurrence of , N'
which means unexpected matches.
To improve your regex you should 1) make .*
ungreedy 2) remove (?s)
3) escape (
:
(VALUES \().*?, (N')
To be more precise in matching you'd better search for:
VALUES \(\K\d+, *(?=N')
and replace with nothing.
Breakdown:
VALUES \(
March VALUES (
literally\K
Reset match\d+, *
Match digits preceding a comma and optional spaces(?=N')
Followed by N'
Upvotes: 1
Reputation: 626728
You may use
(VALUES \().*?,\s*(N')
and replace with $1$2
. Note that in case the part of string to be removed can contain line breaks, enable the .
matches newline. If the N
and VALUES
must be matched only when in ALLCAPS, make sure the Match case option is checked.
Pattern details
(VALUES \()
- Group 1 (later referred with $1
from the replacement pattern): a literal substring VALUES (
.*?
- any 0+ chars, as few as possible, up to the leftmost occurrence of the sunsequent subpatterns,\s*
- a comma and 0+ whitespaces (use \h
instead of \s
to only match horizontal whitespace chars)(N')
- Group 2 (later referred with $2
from the replacement pattern): a literal substring N'
.Upvotes: 1