PDA

View Full Version : LUA Pattern matching issue with FGU versus FGC



celestian
October 22nd, 2020, 15:19
I posted this in the Workshop but this should go here.

I noticed when parsing text from story entries that in FGC I would get a different result than if I ran it in FGU (same code).

The pattern match was this:


local sNoteText = DB.getValue(nodeStory,"text","");
local nStart, nEnd = string.find(sNoteText,'<linklist>[^<]+<link class="imagewindow" recordname="[^\"]+">[^<]+</link>[^<]+</linklist>',1);


(note the bold sections that will be missing in later examples)

Trying to match this:


<p>Links here:</p>
<linklist>
<link class="imagewindow" recordname="image.id-00003">wizard-token</link>
</linklist>


The pattern would match in FGC but not FGU.

Then I tried changing the FGU pattern matching to:


local nStart, nEnd = string.find(sNoteText,'<linklist><link class="imagewindow" recordname="[^\"]+">[^<]+</link></linklist>',1);


At which point it matched in FGU... which seems to indicate that the "newline"chars in FGU are somehow ignored/removed/something.

gamerhawaii
October 22nd, 2020, 16:24
Also, since in your example the "<link" is indented, wouldn't that mean that the whitespace was also ignored/removed/something?

celestian
October 22nd, 2020, 17:11
Also, since in your example the "<link" is indented, wouldn't that mean that the whitespace was also ignored/removed/something?

That's just how the xml file was formatted I copied it from.

FGC console log looks like this:


Runtime Notice: s'manager_author_adnd.lua' | s'createBlocks' | s'sNoteText' | s'
<p>Links here:</p>
<linklist>
<link class="imagewindow" recordname="image.id-00003">wizard-token</link>
</linklist>'


FGU console log looks like this:


[10/22/2020 11:09:59 AM] s'manager_author_adnd.lua' | s'createBlocks' | s'sNoteText' | s'<p>Add links below.</p><linklist><link class="imagewindow" recordname="image.id-00002">Image tsr</link></linklist>'


As you can see, the FGU version doesn't have the actual newlines.

Moon Wizard
October 22nd, 2020, 22:50
The fragment support for the XML engine in FGU is different, and writes it in a more concise format.

Have you tried using '*', instead of '+' for matching in between tags?
local nStart, nEnd = string.find(sNoteText,'<linklist>[^<]*<link class="imagewindow" recordname="[^\"]+">[^<]+</link>[^<]*</linklist>',1);

Regards,
JPG

celestian
October 23rd, 2020, 08:15
The fragment support for the XML engine in FGU is different, and writes it in a more concise format.

Have you tried using '*', instead of '+' for matching in between tags?
local nStart, nEnd = string.find(sNoteText,'<linklist>[^<]*<link class="imagewindow" recordname="[^\"]+">[^<]+</link>[^<]*</linklist>',1);

Regards,
JPG

My memory recall suggests that when I tried that originally it would capture "<linklist>*"... and matching everything after that no matter what. I'll test it tomorrow and see if my memory is correct.

For now, what I've done is create 2 patterns, one for FGC and one for FGU. Based on the version running it uses the correct one. I posted here as you had once said you'd like to see reports on different behaviors between FGC/FGU.