+2  A: 

I did this:

regex = /^(\s*)(.*)\((.*)\)$/

and printed $1#$2($3)# on a match.

It had no effect on my text file.
Bowe
it needs global and multiline flags /^(\s*)(.*)\((.*)\)$/gmglobal -> get all the matches;multiline -> '^' represents start of line (not start of string) and '$' represents end of line (not end of string)
Biroka
@Biroka: multiline mode is usually the default in a text editor, and the global part is achieved by clicking on `Replace All` instead of `Replace`. @Bowe: did you remove slashes at the ends?
Alan Moore
@Alan Moore: No I didn't remove the slashes, you're right. It does work without them. Sorry, user30997, my bad.
Bowe
What does the ($3) do? It seems to work without it also.
Bowe
`($3)` reinserts the parentheses and whatever was inside them.
Alan Moore
+1  A: 

UPDATE:

Ok, [^(]+ in jEdit default regex flag, eaten \n too (I don't see any options to set multiline flag in jEdit search/replace UI),

So, here is new one, confirmed with your updated text

Search: ^(\s*)([^(\n]+\([^)\n]*\))\s*$
Replace: $1#$2

--- previous answer ---

Jedit,

Search : ^(\s*)([^(]+\([^)]+\))\s*$
Replace : $1#$2

--- previous previous Answer ---

Python, '^(\s*)([^(]+\([^)]+\))\s*$'

>>> import re
>>>
>>> re.sub('^(\s*)([^(]+\([^)]+\))\s*$','\\1#\\2','Total reimbursements (before end of Q1)')
'#Total reimbursements (before end of Q1)'
>>>
>>> re.sub('^(\s*)([^(]+\([^)]+\))\s*$','\\1#\\2','                             Total reimbursements (before end of Q1)')
'                             #Total reimbursements (before end of Q1)'
  • assuming there is only one bracket in the line
  • \s* in the end would not need, if there is trailing spaces
  • you would probably need re.MULTILINE flag too, if you want to process multiple lines in one shot.
S.Mark
Tried it on one sample where there is no text between the parentheses and it had no effect there. On a different sample where there is text between the parentheses, it puts the pound sign earlier in the file rather than on the same line where the match ocurred.
Bowe
To match `()`, changing `[^)]+` to `[^)]*` would work
S.Mark
Thanks for the screenshot. Those are the settings I'm using also. It just doesn't seem to work on my test files.
Bowe
Could you provide more test patterns in the question?
S.Mark
Thanks for persevering. I added some new test cases above.
Bowe
confirmed and updated the regex pattern.
S.Mark
Yes! It works! The only change that's needed to your "Replace" pattern is the trailing pound sign which you forgot. So, with this replace pattern it works perfectly: $1#$2# Thanks!
Bowe
Upon further testing, this didn't work as well as Alan Moore's solution.
Bowe
A: 

Try the following:

^\s*(?=((.*)(?<=\((.*)\))$))|(?<=\((.*)\))$

It looks ahead and behind to match lines with a closing bracket at the end of the line only if preceded by an opening bracket.

Replacing with a hash will give you the desired output, it will strip the whitespace at the start of the line also, not suer if this is your desired goal but seems most likely.

Justin Wignall
I got this error when I ran it in Jedit: java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum length near index 23
Bowe
Yes, that's an invalid regex in Java, as it is in most other regex flavors. It works in EditPadPro, but as you said, it strips leading leading whitespace--including blank lines.
Alan Moore
+2  A: 

Regex:

^([ \t]*)(.*\(.*\))$

Replacement:

$1#$2#

The trickiest thing is making sure no part of the regex can match newlines. That's why I used [ \t]* instead of \s* and .* instead of [^(]* or [^)]*.

Alan Moore
This is the only solution here that has worked flawlessly against all of my test files. Thanks a lot!!
Bowe