UltraEdit (or MacOS regex): Delete multiple lines in xml
I have an unformatted xml file in which I would like to delete tags of a specific name that contain some value.
Example:
<XmlElement1>
</XmlElement1>
<XmlElement2 ... >
...
<Xml1SubElement someParameter="...SearchTerm..."/>
...
</XmlElement2>
<XmlElement3/>
... stands for random characters and random multiple lines
In above example I would like to delete all XmlElement2 elements that contain "SearchTerm" in the body. In other words select all text between <XmlElement2
and </XmlElement2>
across multiple lines where SearchTerm
is in the middle and replace with "".
I'm using UltraEdit on MacOS and am flexible with what tools to use.
Your help is much appreciated!
regex newline ultraedit
add a comment |
I have an unformatted xml file in which I would like to delete tags of a specific name that contain some value.
Example:
<XmlElement1>
</XmlElement1>
<XmlElement2 ... >
...
<Xml1SubElement someParameter="...SearchTerm..."/>
...
</XmlElement2>
<XmlElement3/>
... stands for random characters and random multiple lines
In above example I would like to delete all XmlElement2 elements that contain "SearchTerm" in the body. In other words select all text between <XmlElement2
and </XmlElement2>
across multiple lines where SearchTerm
is in the middle and replace with "".
I'm using UltraEdit on MacOS and am flexible with what tools to use.
Your help is much appreciated!
regex newline ultraedit
add a comment |
I have an unformatted xml file in which I would like to delete tags of a specific name that contain some value.
Example:
<XmlElement1>
</XmlElement1>
<XmlElement2 ... >
...
<Xml1SubElement someParameter="...SearchTerm..."/>
...
</XmlElement2>
<XmlElement3/>
... stands for random characters and random multiple lines
In above example I would like to delete all XmlElement2 elements that contain "SearchTerm" in the body. In other words select all text between <XmlElement2
and </XmlElement2>
across multiple lines where SearchTerm
is in the middle and replace with "".
I'm using UltraEdit on MacOS and am flexible with what tools to use.
Your help is much appreciated!
regex newline ultraedit
I have an unformatted xml file in which I would like to delete tags of a specific name that contain some value.
Example:
<XmlElement1>
</XmlElement1>
<XmlElement2 ... >
...
<Xml1SubElement someParameter="...SearchTerm..."/>
...
</XmlElement2>
<XmlElement3/>
... stands for random characters and random multiple lines
In above example I would like to delete all XmlElement2 elements that contain "SearchTerm" in the body. In other words select all text between <XmlElement2
and </XmlElement2>
across multiple lines where SearchTerm
is in the middle and replace with "".
I'm using UltraEdit on MacOS and am flexible with what tools to use.
Your help is much appreciated!
regex newline ultraedit
regex newline ultraedit
asked Jan 2 at 21:00
Bernie LenzBernie Lenz
557419
557419
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The Perl regular expression search string for this task can be for example:
(?s)^[t ]*<XmlElement2(?:.(?!</XmlElement2>))+?SearchTerm.+?</XmlElement2>[t ]*(?:r?n|r)
Explanation:
(?s)
... flag to match newline characters also by dot in search expression.
^[t ]*
... start search at beginning of a line and match 0 or more tabs or spaces.
<XmlElement2
... the start tag of the element to remove on containing SearchTerm
.
(?:.(?!</XmlElement2>))+?
... a non marking group to find any character one or more times non-greedy as long as the string after the current character is not </XmlElement2>
. The negative lookahead (?!</XmlElement2>)
prevents selecting a block starting with <XmlElement2
and matching anything including one or even more </XmlElement2>
and <XmlElement2
tags until SearchTerm
is found anywhere in file.
SearchTerm
... string which must be found inside element XmlElement2
.
.+?
... any character (including newline characters) one or more times non-greedy. Non-greedy means here to stop matching characters on next occurrence of </XmlElement2>
and not on last occurrence of </XmlElement2>
in file.
</XmlElement2>
... the end tag of the XML element to remove on containing SearchTerm
.
[t ]*(?:r?n|r)
... 0 or more tabs or spaces and either DOS/Windows (carriage return + line-feed) or UNIX (just line-feed) or MAC (just carriage return) line ending.
PS: The Perl regular expression replace was tested with UltraEdit for Windows v22.20.0.49 on Windows XP and v25.20.0.88 on Windows 7 as I don't have a Mac.
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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%2fstackoverflow.com%2fquestions%2f54013115%2fultraedit-or-macos-regex-delete-multiple-lines-in-xml%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
The Perl regular expression search string for this task can be for example:
(?s)^[t ]*<XmlElement2(?:.(?!</XmlElement2>))+?SearchTerm.+?</XmlElement2>[t ]*(?:r?n|r)
Explanation:
(?s)
... flag to match newline characters also by dot in search expression.
^[t ]*
... start search at beginning of a line and match 0 or more tabs or spaces.
<XmlElement2
... the start tag of the element to remove on containing SearchTerm
.
(?:.(?!</XmlElement2>))+?
... a non marking group to find any character one or more times non-greedy as long as the string after the current character is not </XmlElement2>
. The negative lookahead (?!</XmlElement2>)
prevents selecting a block starting with <XmlElement2
and matching anything including one or even more </XmlElement2>
and <XmlElement2
tags until SearchTerm
is found anywhere in file.
SearchTerm
... string which must be found inside element XmlElement2
.
.+?
... any character (including newline characters) one or more times non-greedy. Non-greedy means here to stop matching characters on next occurrence of </XmlElement2>
and not on last occurrence of </XmlElement2>
in file.
</XmlElement2>
... the end tag of the XML element to remove on containing SearchTerm
.
[t ]*(?:r?n|r)
... 0 or more tabs or spaces and either DOS/Windows (carriage return + line-feed) or UNIX (just line-feed) or MAC (just carriage return) line ending.
PS: The Perl regular expression replace was tested with UltraEdit for Windows v22.20.0.49 on Windows XP and v25.20.0.88 on Windows 7 as I don't have a Mac.
add a comment |
The Perl regular expression search string for this task can be for example:
(?s)^[t ]*<XmlElement2(?:.(?!</XmlElement2>))+?SearchTerm.+?</XmlElement2>[t ]*(?:r?n|r)
Explanation:
(?s)
... flag to match newline characters also by dot in search expression.
^[t ]*
... start search at beginning of a line and match 0 or more tabs or spaces.
<XmlElement2
... the start tag of the element to remove on containing SearchTerm
.
(?:.(?!</XmlElement2>))+?
... a non marking group to find any character one or more times non-greedy as long as the string after the current character is not </XmlElement2>
. The negative lookahead (?!</XmlElement2>)
prevents selecting a block starting with <XmlElement2
and matching anything including one or even more </XmlElement2>
and <XmlElement2
tags until SearchTerm
is found anywhere in file.
SearchTerm
... string which must be found inside element XmlElement2
.
.+?
... any character (including newline characters) one or more times non-greedy. Non-greedy means here to stop matching characters on next occurrence of </XmlElement2>
and not on last occurrence of </XmlElement2>
in file.
</XmlElement2>
... the end tag of the XML element to remove on containing SearchTerm
.
[t ]*(?:r?n|r)
... 0 or more tabs or spaces and either DOS/Windows (carriage return + line-feed) or UNIX (just line-feed) or MAC (just carriage return) line ending.
PS: The Perl regular expression replace was tested with UltraEdit for Windows v22.20.0.49 on Windows XP and v25.20.0.88 on Windows 7 as I don't have a Mac.
add a comment |
The Perl regular expression search string for this task can be for example:
(?s)^[t ]*<XmlElement2(?:.(?!</XmlElement2>))+?SearchTerm.+?</XmlElement2>[t ]*(?:r?n|r)
Explanation:
(?s)
... flag to match newline characters also by dot in search expression.
^[t ]*
... start search at beginning of a line and match 0 or more tabs or spaces.
<XmlElement2
... the start tag of the element to remove on containing SearchTerm
.
(?:.(?!</XmlElement2>))+?
... a non marking group to find any character one or more times non-greedy as long as the string after the current character is not </XmlElement2>
. The negative lookahead (?!</XmlElement2>)
prevents selecting a block starting with <XmlElement2
and matching anything including one or even more </XmlElement2>
and <XmlElement2
tags until SearchTerm
is found anywhere in file.
SearchTerm
... string which must be found inside element XmlElement2
.
.+?
... any character (including newline characters) one or more times non-greedy. Non-greedy means here to stop matching characters on next occurrence of </XmlElement2>
and not on last occurrence of </XmlElement2>
in file.
</XmlElement2>
... the end tag of the XML element to remove on containing SearchTerm
.
[t ]*(?:r?n|r)
... 0 or more tabs or spaces and either DOS/Windows (carriage return + line-feed) or UNIX (just line-feed) or MAC (just carriage return) line ending.
PS: The Perl regular expression replace was tested with UltraEdit for Windows v22.20.0.49 on Windows XP and v25.20.0.88 on Windows 7 as I don't have a Mac.
The Perl regular expression search string for this task can be for example:
(?s)^[t ]*<XmlElement2(?:.(?!</XmlElement2>))+?SearchTerm.+?</XmlElement2>[t ]*(?:r?n|r)
Explanation:
(?s)
... flag to match newline characters also by dot in search expression.
^[t ]*
... start search at beginning of a line and match 0 or more tabs or spaces.
<XmlElement2
... the start tag of the element to remove on containing SearchTerm
.
(?:.(?!</XmlElement2>))+?
... a non marking group to find any character one or more times non-greedy as long as the string after the current character is not </XmlElement2>
. The negative lookahead (?!</XmlElement2>)
prevents selecting a block starting with <XmlElement2
and matching anything including one or even more </XmlElement2>
and <XmlElement2
tags until SearchTerm
is found anywhere in file.
SearchTerm
... string which must be found inside element XmlElement2
.
.+?
... any character (including newline characters) one or more times non-greedy. Non-greedy means here to stop matching characters on next occurrence of </XmlElement2>
and not on last occurrence of </XmlElement2>
in file.
</XmlElement2>
... the end tag of the XML element to remove on containing SearchTerm
.
[t ]*(?:r?n|r)
... 0 or more tabs or spaces and either DOS/Windows (carriage return + line-feed) or UNIX (just line-feed) or MAC (just carriage return) line ending.
PS: The Perl regular expression replace was tested with UltraEdit for Windows v22.20.0.49 on Windows XP and v25.20.0.88 on Windows 7 as I don't have a Mac.
answered Jan 3 at 10:14
MofiMofi
29k83879
29k83879
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f54013115%2fultraedit-or-macos-regex-delete-multiple-lines-in-xml%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