0

I have the following text:

query([[
select *
from ]]..s_Schema..[[Table
where RowNumber = n_Counter
]],{Counter = n_Counter});

I need to find substring n_ that is between ([[ and ]],.

Such a regexp: \(\[\[[.\r\n]+n_[.\r\n]+\]\], doesn't work.

My case seems to be opposite to this one: Regular expressions: find string without substring

Or this: regex match substring unless another substring matches

2
  • What are you actually trying to match/find, and is there also a replacement here? Commented May 7, 2017 at 12:39
  • I believe you need (?s)\[\[(?:(?!\[\[).)*?n_.*?\]\], but I have no idea what you really need to obtain in the end. Commented May 7, 2017 at 13:19

2 Answers 2

1

A literal implementation of your requirement would be:

Find:

\(.*\[\[.*?(n_\w+).*\]\]

Your current regex has several problems, of which perhaps which stands out the most is this:

[.\r\n]

This character class doesn't do what you think; this will match one of the following three things: a literal dot, a carriage return, or a newline. The query code you are trying to match will never match to this.

Demo here:

Regex101

Sign up to request clarification or add additional context in comments.

Comments

0

Do a regular expression find like this:

  • Open Find Dialog
  • Find What: \(\[\[\K.*(?=\]\],)
  • Check regular expression
  • Check . matches newline
  • Click Find Next

Explanation

  • \(\[\[\K starts matching after [[
  • (?=\]\],) is a Lookahead, it matches only if followed by ]],

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.