0
votes

In my script 'matchfile is a filename with or without an extension.

In my text below, there may or may not be [AnyText], and the text between the brackets could be any alphnumeric characters.

How can I match:

some text
\includescore{something}
\includescore{something.ext}
%\includescore{doNOT.match}
\includescore[AnyText]{something}
\includescore[AnyText]{something.ext}
more text

So far I have this:

regexmatch(searchthis, "mi)(?<=(?<!%)\\includescore\{|(?<!%)\\includescore\[\w\]\{)[\w\s\.\+'#-]+\.?[\w\s\.\+'#-]+(?=.*\})", matchfile)

But that can only match:

\includescore{something}
\includescore{something.extension}
\includescore[a]{something}

And I don't want to match if the line is started with a %.

My first idea is to use w+ but Autohotkey won't allow for the unquantified lookbehind.

Actually, I don't even care about matching the square brackets. I only have to match \includescore, the matchfile and the curly brackets.

Is there another way to do this, or do I need to do multiple regex calls?

2
Where does includescore come from in your regex? Please provide some real input and expected output. - Wiktor Stribiżew

2 Answers

0
votes

Perhaps, this is what you want:

mi)^(?:(?<!%)\\includescore(?:\[\w*\])?(?:\{[\w.]*\})|.*matchfile(?:\.\w*)?)

\includescore(?:\[\w*\])?(?:\{[\w.]*\}) will capture all includescores with optional [AnyText] and obligatory {something}.

In case 'matchfile' is not at the beginning of a line, I added .*, and optional extension will be captured with (?:\.\w*)?)

0
votes

I got it working with this:

;Fetch the uncommented inclusion line
regexmatch(searchthis, "mi)(?<=(?<!%)\\includescore).*?{(.*?)}", matchfile)

;Now pull out the bracketed item
regexmatch(matchinclusion, "i)(?:\[.*\])", includeparam)        ;get the parameter

;now pull out the filename with/without the extension
regexmatch(matchinclusion, "i)(?<={)(.*)(?=})", inclusionfile)  ;get the tex name

It matches on all counts, and excludes the line commented with the %.

In Autohotkey, it matches every instance, and only returns the first one.