Jonathan
Jonathan

Reputation: 9151

Multiline regex in VS2015 or NP++

I need to replace the following pattern across multiple files.

this\.dialogs = {.*};

This works fine when I set the single line flag here: https://regex101.com/r/dF2yG3/2

However I can't get this to work in an editor like VS or Notepad++, it will only match a single line.
How do I change the regex or set flags in any of these editors so I can make it span multiple lines?

Upvotes: 4

Views: 456

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626926

Note you would only want to use

(?s)this\.dialogs = \{.*\};

if you want to match a string from this.dialogs = { up to the last }.

To only match up to the closest };, use

(?s)this\.dialogs = \{.*?\};

The (?s) inline modifier forces a dot to match any character inlcuding a newline.

enter image description here

In Notepad++, you can use . matches newline in Notepad++ option in the Find and Replace dialog instead of (?s).

enter image description here

In Visual Studio 2015 (and in VS2012, VS2013, too), you need to use

this\.dialogs = {[\s\S\r]*?};

to match a string from this.dialogs = { up to the closest };

enter image description here

Upvotes: 4

Enissay
Enissay

Reputation: 4953

Escape the brackets and activate . matches newline In notepad:

this\.dialogs = \{.*\};

enter image description here

Or better use this\.dialogs = \{[^}]*\};

Upvotes: 0

Related Questions