Multiline find and replace wrapper with wildcard inside
I'm trying to put a wrapper around a bunch of fields that already exist.
I want to convert this:
<div class="editor-label">
@Html.LabelFor(Function(model) model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.LastName)
</div>
To this:
<div class="field-group">
<div class="editor-label">
@Html.LabelFor(Function(model) model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.LastName)
</div>
</div>
I'm pretty green with Regex, but here's the closet I came so far to matching on the pattern:
<div class="editor-label">(.|rn)*?(</div>)(.|rn)*?(</div>)
Then it could replace with something like this:
<div class="field-group"><div class="editor-label">(.|rn)*?(</div>)(.|rn)*?(</div>)</div>
But that obviously doesn't work. But the idea would be wrapping around the matched value.
When I use the replace in Notepad++, it replaces it with the string (.|rn)*?(</div>) instead of the matched value.
Can I do a wildcard search and replace that persists the original wildcard matched value?
Or somehow wrap the contents another way?
Note: I'm using Notepad++, but I'd gladly use any other text editor that has this kind of functionality.
notepad++ regex find-and-replace
add a comment |
I'm trying to put a wrapper around a bunch of fields that already exist.
I want to convert this:
<div class="editor-label">
@Html.LabelFor(Function(model) model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.LastName)
</div>
To this:
<div class="field-group">
<div class="editor-label">
@Html.LabelFor(Function(model) model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.LastName)
</div>
</div>
I'm pretty green with Regex, but here's the closet I came so far to matching on the pattern:
<div class="editor-label">(.|rn)*?(</div>)(.|rn)*?(</div>)
Then it could replace with something like this:
<div class="field-group"><div class="editor-label">(.|rn)*?(</div>)(.|rn)*?(</div>)</div>
But that obviously doesn't work. But the idea would be wrapping around the matched value.
When I use the replace in Notepad++, it replaces it with the string (.|rn)*?(</div>) instead of the matched value.
Can I do a wildcard search and replace that persists the original wildcard matched value?
Or somehow wrap the contents another way?
Note: I'm using Notepad++, but I'd gladly use any other text editor that has this kind of functionality.
notepad++ regex find-and-replace
Notepad++, right? Not the stock Notepad included in Windows?
– James Brewer
Sep 18 '14 at 22:31
What are you replacing the match with? That seems to be the problem.
– Excellll
Sep 19 '14 at 19:57
@Excellll, I want to basically add a wrapper around content that matches the provided description. If it matches, I want to take the whole text block and add content before and after it.
– KyleMit
Sep 19 '14 at 20:17
Got it. I was more interested in the string you are using to replace the match in Notepad++. That is, what do you have typed in theReplace withfield?
– Excellll
Sep 19 '14 at 20:20
@Excellll, added update
– KyleMit
Sep 19 '14 at 20:32
add a comment |
I'm trying to put a wrapper around a bunch of fields that already exist.
I want to convert this:
<div class="editor-label">
@Html.LabelFor(Function(model) model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.LastName)
</div>
To this:
<div class="field-group">
<div class="editor-label">
@Html.LabelFor(Function(model) model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.LastName)
</div>
</div>
I'm pretty green with Regex, but here's the closet I came so far to matching on the pattern:
<div class="editor-label">(.|rn)*?(</div>)(.|rn)*?(</div>)
Then it could replace with something like this:
<div class="field-group"><div class="editor-label">(.|rn)*?(</div>)(.|rn)*?(</div>)</div>
But that obviously doesn't work. But the idea would be wrapping around the matched value.
When I use the replace in Notepad++, it replaces it with the string (.|rn)*?(</div>) instead of the matched value.
Can I do a wildcard search and replace that persists the original wildcard matched value?
Or somehow wrap the contents another way?
Note: I'm using Notepad++, but I'd gladly use any other text editor that has this kind of functionality.
notepad++ regex find-and-replace
I'm trying to put a wrapper around a bunch of fields that already exist.
I want to convert this:
<div class="editor-label">
@Html.LabelFor(Function(model) model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.LastName)
</div>
To this:
<div class="field-group">
<div class="editor-label">
@Html.LabelFor(Function(model) model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(Function(model) model.LastName)
</div>
</div>
I'm pretty green with Regex, but here's the closet I came so far to matching on the pattern:
<div class="editor-label">(.|rn)*?(</div>)(.|rn)*?(</div>)
Then it could replace with something like this:
<div class="field-group"><div class="editor-label">(.|rn)*?(</div>)(.|rn)*?(</div>)</div>
But that obviously doesn't work. But the idea would be wrapping around the matched value.
When I use the replace in Notepad++, it replaces it with the string (.|rn)*?(</div>) instead of the matched value.
Can I do a wildcard search and replace that persists the original wildcard matched value?
Or somehow wrap the contents another way?
Note: I'm using Notepad++, but I'd gladly use any other text editor that has this kind of functionality.
notepad++ regex find-and-replace
notepad++ regex find-and-replace
edited Jan 29 '16 at 11:40
Der Hochstapler
67.7k49230284
67.7k49230284
asked Sep 18 '14 at 21:00
KyleMitKyleMit
1,89641732
1,89641732
Notepad++, right? Not the stock Notepad included in Windows?
– James Brewer
Sep 18 '14 at 22:31
What are you replacing the match with? That seems to be the problem.
– Excellll
Sep 19 '14 at 19:57
@Excellll, I want to basically add a wrapper around content that matches the provided description. If it matches, I want to take the whole text block and add content before and after it.
– KyleMit
Sep 19 '14 at 20:17
Got it. I was more interested in the string you are using to replace the match in Notepad++. That is, what do you have typed in theReplace withfield?
– Excellll
Sep 19 '14 at 20:20
@Excellll, added update
– KyleMit
Sep 19 '14 at 20:32
add a comment |
Notepad++, right? Not the stock Notepad included in Windows?
– James Brewer
Sep 18 '14 at 22:31
What are you replacing the match with? That seems to be the problem.
– Excellll
Sep 19 '14 at 19:57
@Excellll, I want to basically add a wrapper around content that matches the provided description. If it matches, I want to take the whole text block and add content before and after it.
– KyleMit
Sep 19 '14 at 20:17
Got it. I was more interested in the string you are using to replace the match in Notepad++. That is, what do you have typed in theReplace withfield?
– Excellll
Sep 19 '14 at 20:20
@Excellll, added update
– KyleMit
Sep 19 '14 at 20:32
Notepad++, right? Not the stock Notepad included in Windows?
– James Brewer
Sep 18 '14 at 22:31
Notepad++, right? Not the stock Notepad included in Windows?
– James Brewer
Sep 18 '14 at 22:31
What are you replacing the match with? That seems to be the problem.
– Excellll
Sep 19 '14 at 19:57
What are you replacing the match with? That seems to be the problem.
– Excellll
Sep 19 '14 at 19:57
@Excellll, I want to basically add a wrapper around content that matches the provided description. If it matches, I want to take the whole text block and add content before and after it.
– KyleMit
Sep 19 '14 at 20:17
@Excellll, I want to basically add a wrapper around content that matches the provided description. If it matches, I want to take the whole text block and add content before and after it.
– KyleMit
Sep 19 '14 at 20:17
Got it. I was more interested in the string you are using to replace the match in Notepad++. That is, what do you have typed in the
Replace with field?– Excellll
Sep 19 '14 at 20:20
Got it. I was more interested in the string you are using to replace the match in Notepad++. That is, what do you have typed in the
Replace with field?– Excellll
Sep 19 '14 at 20:20
@Excellll, added update
– KyleMit
Sep 19 '14 at 20:32
@Excellll, added update
– KyleMit
Sep 19 '14 at 20:32
add a comment |
1 Answer
1
active
oldest
votes
You can do this with the regex substitution engine which is exposed through the Find and Replace feature in notepad. But first, you'll need to be a little familiar with how any regex is able to find and replace text.
Some Regex Info
Capturing Groups:
(ABC)- capturing group - Groups multiple tokens together and creates a capture group
(?:ABC)- non-capturing group - Groups tokens together without creating a capture group
n- backreference - Matches the results of a previous capture group (ex.1)
Substitution Symbols:
$&- match - Inserts the entire matched text.
$n- capture group #n - Inserts the results of the specified capture group (ex.$1)
How to Wrap with Regex Substitution
To wrap any text, first right a regex query to find it. Then replace that entire string with a new one composed of the text you'd like to wrap around it and the original matched text by using $&.
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var wrapMe = 'WrapMe';
var wrapped = wrapMe.replace(/WrapMe/g, "<wrapper> $& </wrapper>");
console.log(wrapped); // <wrapper> WrapMe </wrapper>
To wrap the entire regex query with a substitution
How to Insert with Regex Substitution
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var insertMe = '<wrapper>Replace</wrapper>';
var inserted = insertMe.replace(/(<wrapper>).*(</wrapper>)/g, "$1 Inserted $2");
console.log(inserted); // <wrapper> Inserted </wrapper>
The Problem at Hand
Knowing all that, the problem at hand in Notepad (or anywhere else) should seem rather trivial:
Here's a Demo in RegExr:
Search For: <div class="editor-label">((.|n)*?(</div>)){2,2}
Replace With: <div class="field-group">n$&n</div>
You can pull up the Find and Replace with Ctrl + H

Note: Remember to set the search mode as Regular Expression and also that notepad typically requires
rnto find a newline instead of justn
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f813677%2fmultiline-find-and-replace-wrapper-with-wildcard-inside%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can do this with the regex substitution engine which is exposed through the Find and Replace feature in notepad. But first, you'll need to be a little familiar with how any regex is able to find and replace text.
Some Regex Info
Capturing Groups:
(ABC)- capturing group - Groups multiple tokens together and creates a capture group
(?:ABC)- non-capturing group - Groups tokens together without creating a capture group
n- backreference - Matches the results of a previous capture group (ex.1)
Substitution Symbols:
$&- match - Inserts the entire matched text.
$n- capture group #n - Inserts the results of the specified capture group (ex.$1)
How to Wrap with Regex Substitution
To wrap any text, first right a regex query to find it. Then replace that entire string with a new one composed of the text you'd like to wrap around it and the original matched text by using $&.
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var wrapMe = 'WrapMe';
var wrapped = wrapMe.replace(/WrapMe/g, "<wrapper> $& </wrapper>");
console.log(wrapped); // <wrapper> WrapMe </wrapper>
To wrap the entire regex query with a substitution
How to Insert with Regex Substitution
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var insertMe = '<wrapper>Replace</wrapper>';
var inserted = insertMe.replace(/(<wrapper>).*(</wrapper>)/g, "$1 Inserted $2");
console.log(inserted); // <wrapper> Inserted </wrapper>
The Problem at Hand
Knowing all that, the problem at hand in Notepad (or anywhere else) should seem rather trivial:
Here's a Demo in RegExr:
Search For: <div class="editor-label">((.|n)*?(</div>)){2,2}
Replace With: <div class="field-group">n$&n</div>
You can pull up the Find and Replace with Ctrl + H

Note: Remember to set the search mode as Regular Expression and also that notepad typically requires
rnto find a newline instead of justn
add a comment |
You can do this with the regex substitution engine which is exposed through the Find and Replace feature in notepad. But first, you'll need to be a little familiar with how any regex is able to find and replace text.
Some Regex Info
Capturing Groups:
(ABC)- capturing group - Groups multiple tokens together and creates a capture group
(?:ABC)- non-capturing group - Groups tokens together without creating a capture group
n- backreference - Matches the results of a previous capture group (ex.1)
Substitution Symbols:
$&- match - Inserts the entire matched text.
$n- capture group #n - Inserts the results of the specified capture group (ex.$1)
How to Wrap with Regex Substitution
To wrap any text, first right a regex query to find it. Then replace that entire string with a new one composed of the text you'd like to wrap around it and the original matched text by using $&.
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var wrapMe = 'WrapMe';
var wrapped = wrapMe.replace(/WrapMe/g, "<wrapper> $& </wrapper>");
console.log(wrapped); // <wrapper> WrapMe </wrapper>
To wrap the entire regex query with a substitution
How to Insert with Regex Substitution
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var insertMe = '<wrapper>Replace</wrapper>';
var inserted = insertMe.replace(/(<wrapper>).*(</wrapper>)/g, "$1 Inserted $2");
console.log(inserted); // <wrapper> Inserted </wrapper>
The Problem at Hand
Knowing all that, the problem at hand in Notepad (or anywhere else) should seem rather trivial:
Here's a Demo in RegExr:
Search For: <div class="editor-label">((.|n)*?(</div>)){2,2}
Replace With: <div class="field-group">n$&n</div>
You can pull up the Find and Replace with Ctrl + H

Note: Remember to set the search mode as Regular Expression and also that notepad typically requires
rnto find a newline instead of justn
add a comment |
You can do this with the regex substitution engine which is exposed through the Find and Replace feature in notepad. But first, you'll need to be a little familiar with how any regex is able to find and replace text.
Some Regex Info
Capturing Groups:
(ABC)- capturing group - Groups multiple tokens together and creates a capture group
(?:ABC)- non-capturing group - Groups tokens together without creating a capture group
n- backreference - Matches the results of a previous capture group (ex.1)
Substitution Symbols:
$&- match - Inserts the entire matched text.
$n- capture group #n - Inserts the results of the specified capture group (ex.$1)
How to Wrap with Regex Substitution
To wrap any text, first right a regex query to find it. Then replace that entire string with a new one composed of the text you'd like to wrap around it and the original matched text by using $&.
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var wrapMe = 'WrapMe';
var wrapped = wrapMe.replace(/WrapMe/g, "<wrapper> $& </wrapper>");
console.log(wrapped); // <wrapper> WrapMe </wrapper>
To wrap the entire regex query with a substitution
How to Insert with Regex Substitution
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var insertMe = '<wrapper>Replace</wrapper>';
var inserted = insertMe.replace(/(<wrapper>).*(</wrapper>)/g, "$1 Inserted $2");
console.log(inserted); // <wrapper> Inserted </wrapper>
The Problem at Hand
Knowing all that, the problem at hand in Notepad (or anywhere else) should seem rather trivial:
Here's a Demo in RegExr:
Search For: <div class="editor-label">((.|n)*?(</div>)){2,2}
Replace With: <div class="field-group">n$&n</div>
You can pull up the Find and Replace with Ctrl + H

Note: Remember to set the search mode as Regular Expression and also that notepad typically requires
rnto find a newline instead of justn
You can do this with the regex substitution engine which is exposed through the Find and Replace feature in notepad. But first, you'll need to be a little familiar with how any regex is able to find and replace text.
Some Regex Info
Capturing Groups:
(ABC)- capturing group - Groups multiple tokens together and creates a capture group
(?:ABC)- non-capturing group - Groups tokens together without creating a capture group
n- backreference - Matches the results of a previous capture group (ex.1)
Substitution Symbols:
$&- match - Inserts the entire matched text.
$n- capture group #n - Inserts the results of the specified capture group (ex.$1)
How to Wrap with Regex Substitution
To wrap any text, first right a regex query to find it. Then replace that entire string with a new one composed of the text you'd like to wrap around it and the original matched text by using $&.
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var wrapMe = 'WrapMe';
var wrapped = wrapMe.replace(/WrapMe/g, "<wrapper> $& </wrapper>");
console.log(wrapped); // <wrapper> WrapMe </wrapper>
To wrap the entire regex query with a substitution
How to Insert with Regex Substitution
Here's a Demo in RegExr:

Here's an Example with JavaScript:
var insertMe = '<wrapper>Replace</wrapper>';
var inserted = insertMe.replace(/(<wrapper>).*(</wrapper>)/g, "$1 Inserted $2");
console.log(inserted); // <wrapper> Inserted </wrapper>
The Problem at Hand
Knowing all that, the problem at hand in Notepad (or anywhere else) should seem rather trivial:
Here's a Demo in RegExr:
Search For: <div class="editor-label">((.|n)*?(</div>)){2,2}
Replace With: <div class="field-group">n$&n</div>
You can pull up the Find and Replace with Ctrl + H

Note: Remember to set the search mode as Regular Expression and also that notepad typically requires
rnto find a newline instead of justn
answered Dec 18 '14 at 22:14
KyleMitKyleMit
1,89641732
1,89641732
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f813677%2fmultiline-find-and-replace-wrapper-with-wildcard-inside%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Notepad++, right? Not the stock Notepad included in Windows?
– James Brewer
Sep 18 '14 at 22:31
What are you replacing the match with? That seems to be the problem.
– Excellll
Sep 19 '14 at 19:57
@Excellll, I want to basically add a wrapper around content that matches the provided description. If it matches, I want to take the whole text block and add content before and after it.
– KyleMit
Sep 19 '14 at 20:17
Got it. I was more interested in the string you are using to replace the match in Notepad++. That is, what do you have typed in the
Replace withfield?– Excellll
Sep 19 '14 at 20:20
@Excellll, added update
– KyleMit
Sep 19 '14 at 20:32