Difference in regular expressions between Search and Function List?
-
Hi, I’ve been working on this problem all day and have read numerous posts but I’m still stuck and hope someone can help. I’m trying to build a function list in Notepad++ for a custom language. A function in the language is a function name followed by a colon and then other stuff. I want to get the Function List panel to show the list of function names. The regular expression “^.*?:” works if I use the regular expression match in Find and say “Find all in current document.” However, it doesn’t work if I put that exact same regular expression into the language XML file. It finds far fewer matches and shows text from the wrong lines. Can anyone help?
-
@RobertE ,
You presumably have something like this:
function1: normal text normal text function2: normal text function3: function4: function5: function6: function7: function8: function9:
… where you are seeing “normal text” showing up.
This is because in your search dialog, you do not have
. matches newline
checkmarked; unfortunately for you, the regex for FunctionList definitions defaults to having. matches newline
active. You just need a regex that turns it off using the(?-s)
syntax. Something like:<?xml version="1.0" encoding="UTF-8" ?> <NotepadPlus> <functionList> <parser displayName="Example" id="example_syntax" commentExpr="" > <function mainExpr="(?-s)^.*?:" > <functionName> <nameExpr expr="(?-s)^.*?:" /> </functionName> </function> </parser> </functionList> </NotepadPlus>
gives
That should solve the problem of “shows text from the wrong lines”.
I am hoping that “finds far fewer matches” will go away after that is fixed. (I say this because what’s matching is lines 2-5 match the multiline
^.*?:
because there are no colons between, but FunctionList will only show the first line of the match if your functionList definition matches multiple lines for the same function; from your perspective, this “gobbles up”function2:
, making it not show that one. Similarly, lines 6-8 are the second “normal text” in the FunctionList, so it “gobbles up”function3
(I should have used different text on each of those lines to be more obvious, but didn’t think of that until after creating the screenshots/data/etc.). Sincefunction2
andfunction3
are gobbled up, I believe that’s why you think there are too few.If you still have too few after fixing the regex to not allow multiline functions, please show an example of your dataset that gives too few functions (use the
</>
button in the forum to mark the data as code/plaintext), along with another text-block that has your functionList definition file (similar to my two blocks, above). Forcing us to re-create everything from scratch means we will have to do more work (and we will probably guess wrong as well), whereas if you share the data and config file with us, it will be a simple copy/paste for us. -
@PeterJones Wow, thank you so much! That definitely fixes the “Shows text from wrong lines” problem. I’m still not getting as many hits in the function list as I should but let me play around with that for a while and see if I can figure it out. If I can’t, I’ll write again and post my data set and the config file that I’m using. I might have to wait till the weekend to work on it again. Thanks so much for your help!
-
@PeterJones Just wanted to let you know that after I closed down Notepad++ and reopened it, now the Function List works perfectly in all files. Thanks again.