With single line it's plain simple. But I could not find a way of replacing a block of text, not with structural replace, nor with replace in path of course. And replacing multiple times, just line by line isn't an option.
Thanks.
Try the following: Convert the existing profile contents to a multiline string - by default Get-Content returns an array of strings, just pipe it to Out-String. You'll need a regex "mode-modifier" to ensure the statement searches multiple lines and the wildcard includes line breaks - see here for an explanation.
It's easy to do multiline replace in Notepad++. You have to use \n to represent the newline in your string, and it works for both search and replace strings.
CHANGE: The default keyboard shortcut for “Multiline Find/Replace” was Ctrl+Alt+F but it was not applied because this shortcut was already taken by “F# Interactive”. So, the new default shortcut is Ctrl+M, Ctrl+F.
When you try to paste in a couple of lines into the find field, only the first line is entered, rest is ignored. Thanks to a little plugin called ToolBucket, we can now find and replace multi-line text in Notepad++.
The following `sed` command will replace all lines that start with the word, ‘It’ by the word, ‘ This line is replaced ‘. The following output will appear after running the commands. Three lines contain the word ‘ It ‘ in the file. So, these lines have been replaced by the replacement text.
TextCrawler is one of the best tools to find and replace text across multiple files which can be used by both beginner and advanced users.
Under the Available tab, find and select ToolBucket, and click Install. Once installed, press Alt+Shift+F key combination to open Multi-line Find and Replace dialog. From here, you can search for text within a particular text selection, current document, or in all the open documents. Find and Replace is not the only feature you get with ToolBucket.
"Replace in Path" has an option to use regex.
To replace a block of text you can describe the block as a regex, using \n or \r\n for the line breaks (depending on your line-ending \n for LF and \r for CR).
If you are not familiar with regex yet, you can use a handy feature of IntelliJ:
=> If the block of text is multiline IntelliJ will automagically check the regex option and put a fully escaped (including line breaks) version of your selected text in the search dialog. All you have to do now is enter the replace text and start the search.
BTW: "Structural Replace" does allow to replace multiline blocks of text/code. But plain text (without any variables) is not accepted as a valid search pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With