I’m trying to write a regex in a split expression to pull the device (PLC) name from the OPCItemPath of a tag, but what I have seems to be pulling the inverse of what I’m expecting and what online resources tell me should work.
I have this so far:
split(toStr(tag("Receivals/Crushers/Crusher 1/AV01.OPCItemPath")), "\\[(.*?)\\]")
If the returned string from the tag read is:
I expect the returned value to be:
However, the returned dataset for the above split is this:
[0,0] => "ns=1;s=" [1,0] => "C1_AV01.Sts"
which completely misses the string in square brackets…
This same regex (minus escape characters for the backslashes required by Ignition, e.g.
\[(.*?)\] )works in an online regex tester (https://regexr.com) and is also a solution from a Stack Overflow post (https://stackoverflow.com/questions/2403122/regular-expression-to-extract-text-between-square-brackets) where it returns:
which is far closer to what I want… I still don’t know how to remove the brackets though, using the regex language.
Can someone please clue me in on what I’m missing here?
It looks like
(?<=\[).+?(?=\]) should be the regex expression to remove the brackets, however this is still not returning the text within the brackets, but rather the text either side of the brackets… Again, this works as expected using the online tester.