From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
We all know that regular expressions (regexes) are extremely powerful for many string operations, including parsing, cleaning, and rearranging. For most of us, however, reading a regex is akin to hieroglyphics, and who really wants to memorize all of those special codes and constructs. This tool allows you to construct and test a regular expression using pulldown menus when you need a reminder of what all of the special codes mean. When you have developed that killer regex, save it as a macro and it will be just a couple of clicks away whenever you need it.
Description
This Tool allows you to develop and test Perl Compatible Regular Expressions (PCRE) used by Match Regular Expression and Search and Replace. They are extremely powerful and flexible, but potentially confusing and frustrating. With this Tool you can load an input string from a file, a URL, or by typing/pasting into the Input string control. Next you can build your regex by hand, with a little help from the pulldown menus when you have forgotten what code to use. When you are ready, press Test or First and you will see the whole match in bold, with underlined and colored submatches. You can use the Prev and Next buttons to find other matches in the Input string.
On the Macros Tab you can add or delete Macros which are stored in a configuration file. I have included a couple of examples, when you understand the Match Parentheses macro, you are on your way to regex ninja-hood.
The Help tab contains a summary of the syntax from the PCRE website. It is searchable as well.
Steps to Implement or Execute Code
I have added this tool to my Tools menu, you can follow the instructions on the block diagram to do so as well. Change the VI to Run when opened, enable the Front Panel Close code in the disable structure, then copy the code to the project folder as shown. The SubVIs are located in a folder which starts with an underscore so they will not appear in the Tools menu.
Requirements to Run
Software
LabVIEW 2009 or later
Hardware
None
Additional Images
Most of the code is fairly straightforward with your typical While Loop/Event Structure to handle the UI. There is one potential surprise lurking when you examine the code which tests the regex, you would probably expect to find a 'Match Regular Expression' function in there somewhere, and you will not (I use it for searching the help). This function is implemented as an XNode, and inside vi.lib are two VIs which serve as the business end of this XNode. They are contained in the two snippets below and I often use them directly.
Other things to note in the code:
I have implemented Ctrl-a (Select All) behavior in the Input String and Regex controls.
The background of the front panel is a transparent classic path control, this allows the panel to act as a drop target for files without calls to Windows API, or other platform-specific functions.
V2 : Fixed Property Nodes, Help Search is case insensitive, coerce issue with LV10.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
"Content-Type Not allowed errors": rename your images with lower case file extensions -> then it's working
Thanks, that did the trick.
Darin, when loading in 2010f2, I get the following load warning for RegexHelper_SetStringPosition.vi:
(RegexHelper_SetStringPosition.vi)
While it probably has no ill effects here, You should make sure to fix the coercion. Nobody wants to see confusing (to some!) popups when loading a released VI.
>> "Drag a file onto the Front Panel (the background is a drop target via a transparent Path control)"
This seems to have the unwelcome side-effect that clicking anywhere on the FP background (=actually the path control) during an editing session, turns the entire FP black and it is not immediately obvious how to get things back to normal. Is there a way to avoid this?
Looks Great! A few minor code simplification suggestions:
In the event cases:
... there are identical property nodes that are used in all cases of a small case structure. These belong after the case structure as a single instance. The current situation creates e.g. problems when searching for a certain property node because there will be an excessive amount of matches, possibly slowing down the programmer.
Thanks for the heads up, I'll check out the LV10 issue, Good catch on the PNs, I rearranged the menus to simplify the UI and did not manage to simplify the code as well. Fixed in next version (posting later today I hope).
I added a visibility toggle to the hidden path control which hides it when the VI is stopped. Now you can click at will in the FP. I use an Event Case to stop clicks when it is running.
Mr. Darin
Is there any possibility to get the presentation about regex from 2016 NI week? Any material from that day would be great.
Its not available on NI app.
I also found the tool expresso extremely helpful in developing regex like a pro: http://www.ultrapico.com/expresso.htm