-1

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&eacute;) again with Mal&eacute; - 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&eacute;) again</p>
<p style="font-family: &quot;verdana&quot;; font-size: 18px; color: rgb(0, 0, 0);">Mal&eacute; again</p>
<style>
code {
 font-family: &quot;verdana&quot;;
 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>
asked Jun 19, 2025 at 14:44
4
  • 5
    It is because you capture the closing parenthesis into group 1 here ... \((.+?\))\s*again. Fix it by moving it out like so: ... \((.+?)\)\s*again Commented Jun 19, 2025 at 15:28
  • 1
    Use (?:<!--.*?-->|<style(?s:.*?)</style>|<script(?s:.*?)</script>|rgb\(\d+, \d+, \d+\))(*SKIP)(*F)|\(([^()]*)\)\s*again. See demo. Commented Jun 19, 2025 at 17:10
  • If those are HTML files, why not use HTML parser? Commented Jun 20, 2025 at 9:28
  • @MichałTurczyn Please let me know which HTML parser to use in this case and how to use it. Commented Jun 20, 2025 at 16:08

3 Answers 3

0

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&eacute;) again</p>
<p style="font-family: &quot;verdana&quot;; font-size: 18px; color: rgb(0, 0, 0);">Mal&eacute; again</p>
<style>
code {
 font-family: &quot;verdana&quot;;
 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&eacute; - again</p>
<p style="font-family: &quot;verdana&quot;; font-size: 18px; color: rgb(0, 0, 0);">Mal&eacute; again</p>
<style>
code {
 font-family: &quot;verdana&quot;;
 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>
answered Jun 23, 2025 at 9:27
Sign up to request clarification or add additional context in comments.

Comments

0

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&emacr;) again</p>
<p style="font-family: &quot;verdana&quot;; font-size: 18px; color: rgb(0, 0, 0);">Mal&emacr; again</p>
<style>
code {
 font-family: &quot;verdana&quot;;
 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&emacr; - again</p>
<p style="font-family: &quot;verdana&quot;; font-size: 18px; color: rgb0, 0, 0 -;">Mal&emacr; again</p>
<style>
code {
 font-family: &quot;verdana&quot;;
 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.

answered Jun 20, 2025 at 14:02

1 Comment

This makes googleTranslateElementInit invalid javascript.
0

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

answered Jul 3, 2025 at 15:50

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.