I would like to match everything after \t(\fn
but only before \
and excluding the last bracket that belongs to the \(t
(as you can see on the attached picture)
For this :
\t(\fnJester (BIG))
\t(\fnJester (BIG))\i1
\t(\fnJester (BIG)
\t(\fnJester))))\fnArial (BOLD)\
I want to match :
Jester (BIG)
Jester (BIG)
Jester (BIG
Jester)))) and Arial (BOLD
I'm almost there with this pattern :
(?<=\\t\(.*?\\fn).*(?=\)|\\)
But since it's greedy, it matches everything even after \
CodePudding user response:
You can match the regular expression
(?<=fn)[^\\]*(?=\)|\\fn)
The expression can be broken down as follows.
(?<= # begin a positive lookbehind
fn # match 'fn'
) # end positive lookbehind
[^\\]* # match zero or more chars other than '\'
(?= # begin a positive lookahead
\) # match ')'
| # or
\\fn # match '\fn\
) # end positive lookahead
CodePudding user response:
You may use this regex:
(?<=\\fn).*?(?=\\fn|\)(?:\\(?!fn)|$))
(?=\\fn|\)(?:\\(?!fn)|$))
is the lookahead condition that is making sure that our match is ending with \fn
or )
followed by optional \
.