I have a couple of sentences in parentheses in a couple of files in a folder and I need to find and remove the opening bracket and replace the closing bracket of every parenthesis with a hyphen/dash (-). I don't know if Notepad++ is the best to use for this but I opened one of those files with Notepad++, selected the Regular Expression mode and put this in the "Find" field:-
(<!--.*?-->|<style[\S\s\n]*?</style>|<script[\S\s\n]*?</script>|rgb\(\d+,\x20\d+,\x20\d+\))(*SKIP)(*F)|\((.+?\))\s*again
and
1ドル - again
in the Replace in files field to replace (Malé) again with Malé - again but when I hit Replace, the closing bracket is not removed. Please give me the correct Regular Expression to replace the parentheses.
This is part of one of the files that can be used as a sample for testing the above RegEx:-
<!-- (Malé) -->
<p>(Malé) again</p>
<p style="font-family: "verdana"; font-size: 18px; color: rgb(0, 0, 0);">Malé again</p>
<style>
code {
font-family: "verdana";
font-size: 18px;
color: black;
font-weight: bold !important;
line-height: 1.6 !important;
}
@media (min-width: 1281px) {
code {
font: 24px "verdana" bold !important;
}
}
</style>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
3 Answers 3
Goal
Removing the opening bracket and replacing the closing bracket with -
Find
(?:<!--.*?-->|<style(?s:.*?)</style>|<script(?s:.*?)</script>|rgb\(\d+,\x20\d+,\x20\d+\))(*SKIP)(*F)|\(([^()]*)\)\s*again
Replace
1ドル - again
Input
<!-- (Malé) -->
<p>(Malé) again</p>
<p style="font-family: "verdana"; font-size: 18px; color: rgb(0, 0, 0);">Malé again</p>
<style>
code {
font-family: "verdana";
font-size: 18px;
color: black;
font-weight: bold !important;
line-height: 1.6 !important;
}
@media (min-width: 1281px) {
code {
font: 24px "verdana" bold !important;
}
}
</style>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
Output
<!-- (Malé) -->
<p>Malé - again</p>
<p style="font-family: "verdana"; font-size: 18px; color: rgb(0, 0, 0);">Malé again</p>
<style>
code {
font-family: "verdana";
font-size: 18px;
color: black;
font-weight: bold !important;
line-height: 1.6 !important;
}
@media (min-width: 1281px) {
code {
font: 24px "verdana" bold !important;
}
}
</style>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
Comments
Goal
Removing open bracket and replace close bracket with -.
Find
(\()((.*?\r?\n)*?.*?)(\))
Replace
2ドル -
Explanations
(\(): the first group matches the open braket((.*?\r?\n)*?.*?): The second and third groups match the characters between the open and closed bracket(\)): the fourth group matches the close braket
Input
<!-- (Male) -->
<p>(Malē) again</p>
<p style="font-family: "verdana"; font-size: 18px; color: rgb(0, 0, 0);">Malē again</p>
<style>
code {
font-family: "verdana";
font-size: 18px;
color: black;
font-weight: bold !important;
line-height: 1.6 !important;
}
@media (min-width: 1281px) {
code {
font: 24px "verdana" bold !important;
}
}
</style>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
Output
<!-- Male - -->
<p>Malē - again</p>
<p style="font-family: "verdana"; font-size: 18px; color: rgb0, 0, 0 -;">Malē again</p>
<style>
code {
font-family: "verdana";
font-size: 18px;
color: black;
font-weight: bold !important;
line-height: 1.6 !important;
}
@media min-width: 1281px - {
code {
font: 24px "verdana" bold !important;
}
}
</style>
<script type="text/javascript">
function googleTranslateElementInit - {
new google.translate.TranslateElement{pageLanguage: 'en'}, 'google_translate_element' -;
}
</script>
Limit
Nested parentheses such as (text(otherText)) are only partially processed.
1 Comment
googleTranslateElementInit invalid javascript.I recommend not doing what youre attempting using that sentence formula there. and obtaining the information attempted to be obtained with the corrections if accurately working
... \((.+?\))\s*again. Fix it by moving it out like so:... \((.+?)\)\s*again(?:<!--.*?-->|<style(?s:.*?)</style>|<script(?s:.*?)</script>|rgb\(\d+, \d+, \d+\))(*SKIP)(*F)|\(([^()]*)\)\s*again. See demo.