I did this:
regex = /^(\s*)(.*)\((.*)\)$/
and printed $1#$2($3)# on a match.
I did this:
regex = /^(\s*)(.*)\((.*)\)$/
and printed $1#$2($3)# on a match.
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)'
\s*
in the end would not need, if there is trailing spacesre.MULTILINE
flag too, if you want to process multiple lines in one shot.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.
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 [^)]*
.