Regular Expressions

Are there any future plans for support of Regular Expressions in action-items?

I’ve got a situation where I’m migrating over some perl-programs which were used to collect data from an OPC server, do some text-conversions and such using regular-expressions, then store the data into a DB. I can ALMOST do everything I need to using a combination of MySQL calls and native action-item functions, but not quite.

I briefly looked into the .net plugin integration, but quickly got lost as I have no experience with .net.

If I spend a LOT of time going through a bunch of PLC-logic & HMI logic, I can change them all to use a common format when sending text-strings to the OPC server, but at this point, thats an enormous job. The old program used Regular Expressions to clean-up the “unknowns” from the various systems (spacing differences, hyphens in some places, colons in others, etc) and store a couple of clean strings in a couple places in the database.

/STATION (\d*)[ -](.$)/i

This regular expression took a string with the text "STATION " in the beginning and stripped out any number of digits followed by any number of spaces or hyphens, and stripped out the remaining text until the end of the string. The digits and the string are the station number & text of the alarm on the machine.

The problem is that the incoming string can take so many forms. Regular Expressions can handle the variability. So far, I can’t find anything to do it in FactorySQL.

Any ideas?

Hmm… we could probably throw together a quick plugin to help you out. It looks like you’re just trying to extract a few specific match groups from a string… we could probably do something like “runRegEx(pattern, value, regexname)” and then “getRegExMatch(regexname, match_index/match_name)”. You would run the first in an action item at the top of the list, and then you could have a few action items that call the second function to get the various values and write them to the DB.

Does this sound like it would work? If so we could probably whip it together fairly quickly.

Regards,

You’re right, I’m basically trying to extract a couple strings. If you wouldn’t mind throwing something together, that would be fantastic.

If this plugin works out, I will have never had a data-collection issue that couldn’t be solved with FactorySQL. I absolutely love the customizability of your software. Keep up the good work!

-Dave

Might want to send a PM to Dravik and see if he is feeling generous - looks like he just wrote the plugin in question (see this thread: viewtopic.php?f=13&t=3760)

Here’s a quick plugin I threw together, hope it does what you want.

There are 2 main functions:
int ExecuteRegEx(string Pattern, string Value, bool IgnoreCase)
string GetRegExGroupMatch(int index)

You would execute the first in an action item which didn’t write back to anything. Then, in any number of following action items, you would call the second function to get the values, and could store them to the database or plc, or do whatever you want with them.

You might need to change your regex syntax to use microsoft’s syntax. This page has some info: http://msdn.microsoft.com/en-us/library/1400241x.aspx.

I tried:

STATION (\\d*)[ -]*(.*$)

and it seemed to work correctly.

The readme.txt has a little bit more info, like how to install.

Let me know if you have any problems/questions!

Regards,
RegExPlugin.zip (5.41 KB)

I should mention a few more things…

  1. There’s a bonus function:
bool IsRegExMatch(string Value, string Pattern, bool IgnoreCase)

that just returns whether there’s a match.

  1. The two functions above operate on match groups. You can make a group in your regex by using parenthesis. Dave has already done this in his expression, but I wanted to point it out to anyone who happens on this thread later.

Regards,