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.
11-26-2014 09:13 PM
Regulex (http://jex.im/regulex) is a good new regex visualizer. Here is a smattering of example visualizations selected from this thread:
Basic regex from http://forums.ni.com/t5/BreakPoint/Regular-Expressions-Board/m-p/2705169/highlight/true#M24349
Backreferences are supported as in http://forums.ni.com/t5/BreakPoint/Regular-Expressions-Board/m-p/2583449/highlight/true#M23742
Note! Javascript-flavored regexes only implement a subset of PCRE (LabVIEW-style) regexes. The following regex shows proper look-ahead support, but does not interpret \z end of subject as a reserved token as with PCRE. For clarity, this is a Javascript-flavor regex deficiency, not a problem with Regulex. From http://forums.ni.com/t5/BreakPoint/Regular-Expressions-Board/m-p/2895480/highlight/true#M25358
Javascript does not support lookbehind at all, as with(?<=\[ABC\]\[)(.*?)(?=\]) from http://forums.ni.com/t5/BreakPoint/Regular-Expressions-Board/m-p/2613621/highlight/true#M23894 -- for this reason, Regulex throws a syntax error.
Here's a list of features not supported by Javascript regexes, so be mindful using Regulex to design or debug PCRE-style regular expressions in LabVIEW!
01-14-2015 06:43 AM
Needed to filter escape codes received over RS232 from a linux box shell response
Used Search and Replace with regex enabled (right-click), replace all and multiline set to true to clean in one swoop.
\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]
Regex from StackOverflow (http://serverfault.com/questions/71285/in-centos-4-4-how-can-i-strip-escape-sequences-from-a-text-fi...
Before:
-rw-r--r-- 1 root root 34816 Jan 13 18:10 [0;0m1k_symphonyconfig.xml[0m -rw-r--r-- 1 root root 5 Jan 13 14:10 [0;0mTZ[0m -rw-r--r-- 1 root root 4 Jan 13 14:10 [0;0mTZ_geoname[0m -rw-rw-rw- 1 root root 63362 Jan 13 14:10 [0;0mbackupconfig.xml[0m -rw-r--r-- 1 root root 0 Jan 13 19:06 [0;0mbadsymconfig.xml[0m -rw-r--r-- 1 root root 155 Jan 13 15:29 [0;0mgroup[0m -rw-rw-rw- 1 root root 13 Jan 13 14:09 [0;0mlast_reboot_reason.txt[0m -rw-r--r-- 1 root root 143 Jan 13 15:30 [0;0mpasswd[0m -rw-r--r-- 1 root root 107 Jan 13 15:30 [0;0mpasswd.old[0m -rw-r--r-- 1 nobody nogroup 0 Jan 13 15:29 [0;0mpostLoginMessage.txt[0m -rw-r--r-- 1 nobody nogroup 904 Jan 13 15:29 [0;0mpreLoginMessage.txt[0m -rw-r----- 1 root root 180 Jan 13 14:10 [0;0mshadow[0m -rw-r----- 1 root root 180 Jan 13 14:10 [0;0mshadow.old[0m -rw-r--r-- 1 root root 1024 Jan 13 15:28 [0;0msymphonyconfig.sec[0m -rw-r--r-- 1 root root 34816 Jan 14 07:37 [0;0msymphonyconfig.xml[0m -rw-r--r-- 1 root root 61905 Jan 13 18:32 [0;0msymphonyconfig.xml.postupgrade[0m -rw-r--r-- 1 root root 0 Jan 13 14:09 [0;0msymphonyconfig.xml.preupgrade[0m -rw-r--r-- 1 root root 106 Jan 13 14:09 [0;0mupgraderlog.txt[0m
After
-rw-r--r-- 1 root root 34816 Jan 13 18:10 1k_symphonyconfig.xml -rw-r--r-- 1 root root 5 Jan 13 14:10 TZ -rw-r--r-- 1 root root 4 Jan 13 14:10 TZ_geoname -rw-rw-rw- 1 root root 63362 Jan 13 14:10 backupconfig.xml -rw-r--r-- 1 root root 0 Jan 13 19:06 badsymconfig.xml -rw-r--r-- 1 root root 155 Jan 13 15:29 group -rw-rw-rw- 1 root root 13 Jan 13 14:09 last_reboot_reason.txt -rw-r--r-- 1 root root 143 Jan 13 15:30 passwd -rw-r--r-- 1 root root 107 Jan 13 15:30 passwd.old -rw-r--r-- 1 nobody nogroup 0 Jan 13 15:29 postLoginMessage.txt -rw-r--r-- 1 nobody nogroup 904 Jan 13 15:29 preLoginMessage.txt -rw-r----- 1 root root 180 Jan 13 14:10 shadow -rw-r----- 1 root root 180 Jan 13 14:10 shadow.old -rw-r--r-- 1 root root 1024 Jan 13 15:28 symphonyconfig.sec -rw-r--r-- 1 root root 34816 Jan 14 07:39 symphonyconfig.xml -rw-r--r-- 1 root root 61905 Jan 13 18:32 symphonyconfig.xml.postupgrade -rw-r--r-- 1 root root 0 Jan 13 14:09 symphonyconfig.xml.preupgrade -rw-r--r-- 1 root root 106 Jan 13 14:09 upgraderlog.txt
02-11-2015 09:51 AM - edited 02-11-2015 09:52 AM
Does anyone know how to configure a regex for parsing a string number from 00.01 to 20.00,
I tried... ^([0-1][0-9]\.[0-9][1-9]|20\.00)$ but it fails when string number is i.e. 00.10 or 10.50.
What can be a better regex for this one?....Thanks
02-03-2017 06:25 AM - edited 02-03-2017 06:33 AM
Needed to split strings received from a linux box shell to separate the command from the response. Shell commands include modifiers and piped output to process data to execute as a single command. These are also regex control characters, so I needed to escape them.
Used Search and Replace with regex enabled (right-click), replace all and multiline set to true to escape in one swoop. Set replace string to \\$1 to place literal backslash (escape) in front of each found regex control character (backreference)
(\.|\+|\*|\?|\[|\^|\]|\$|\(|\)|\{|\}|\=|\!|\<|\>|\||\:|\-)
Whew! Too many backslash and pipe chars for me to digest, but it worked 🙂
Used result string as input to Match Regular Expression as regular expression and now I could separate the response from the command.
Effectively what the PHP preg_quote function does.
02-08-2019 01:38 PM
I'm working on a problem where I am given a function prototype for some C function and am trying to find the name of the variable we will be passing that is a specific, known, type. As an example, for the function prototype below, if I was given the input TESTSTRUCT I would want the function to return "capturedName"
int DoThing(TESTSTRUCT *capturedName,char *otherParameter, double yetAnotherParameter);
I was able to come up with a RegEx which seems to do this for me but I would appreciate any input on how I could simplify what I am doing or cases where my approach may give unexpected results. For the RegEx below, TESTSTRUCT will be replaced with whatever variable type I am looking for.
(?<=[(|\s|,])TESTSTRUCT[\s*|\**]+(\S+?)\s*[,|)]{1}
(?<=[(|\s|,]) - Variable name must be preceeded by comma, parentheses, or space. Prevents type "name" matching "othername"
[\s*|\**]+ - Some combination of * and whitespace between type and variable name (must have at least one of these)
(\S+?) - capture group of 1 or more non-whitespace characters (lazy)
\s* - 0 or more whitespace characters
[,|)]{1} - a comma or end parentheses
In my head I figured this would be a pretty regular pattern but C (CVI at least) seems lenient as far as having (or not having) white space between a lot of definitions.
02-11-2019 10:11 PM
I had a quick go at simplifying the regex (tested with LabVIEW's Match Regular Expression):
\(.*TESTSTRUCT[\s\*]+(\w+)
where:
\(.* - Match the opening parenthesis, followed by zero or more characters
TESTSTRUCT - The type required
[\s\*]+ - One or more space or pointer characters between type and name
(\w+) - The variable name comprising one or more alphanumeric characters
I've omitted the closing parenthesis, assuming the function prototype is valid. Do you need to check for prototype validity?
02-12-2019 10:30 AM
@MichaelBalzer wrote:
I've omitted the closing parenthesis, assuming the function prototype is valid. Do you need to check for prototype validity?
For my use case, I am assuming that the function prototype is valid.
I didn't actually know that \w captured numbers and underscores so I will substitute \s in my original regex for \w. That also lets me omit the last part of my regex which is searching for commas or parentheses which made sure they weren't captured as part of the variable name.
One issue that your regex does have is that it would capture any variable names whose types end with the key word. As an example, the regex would find "capturedName" for both function prototypes below.
int DoThing(TESTSTRUCT *capturedName,char *otherParameter, double yetAnotherParameter);
int DoThing(notTESTSTRUCT *capturedName,char *otherParameter, double yetAnotherParameter);
I haven't tested it fully but right now I'm thinking of combining the start of my original search with the end of your for something like (?<=[(|\s|,])TESTSTRUCT[\s\*]+(\w+)
02-12-2019 07:29 PM
@Jacobson-ni wrote:
One issue that your regex does have is that it would capture any variable names whose types end with the key word. As an example, the regex would find "capturedName" for both function prototypes below.
Good point, I didn't consider that scenario.
An alternative would be to match one or more non-word characters right before TESTSTRUCT, so something like:
\W+TESTSTRUCT[\s\*]+(\w+)
You could even have the following (note the second \W)
\W+TESTSTRUCT\W+(\w+)
FYI the range square brackets implicitly OR the contents, so the pipe char isn't needed. Saves a few chars, though not sure if it helps with readability!
02-13-2019 08:56 AM
@MichaelBalzer wrote:
FYI the range square brackets implicitly OR the contents, so the pipe char isn't needed. Saves a few chars, though not sure if it helps with readability!
I didn't know that but I'll probably keep the pipe because I'll most likely forget this fact.
I'm going to do what I should have done at the start and just make an actual unit test to try these out but I think the last regex you posted may pick up the type of parameter N+1 if the name of the parameter N matches.
06-30-2021 01:32 PM
I used Regular Expressions to solve the FIZZBUZZ programming challenge.
import re
for i in range(1,101):
out = ''
if(re.search('^(0|1(01*0)*1)*$', bin(i)[2:])): out = 'FIZZ'
if(re.search('[0-9]?[05]$', str(i))) : out += 'BUZZ'
if(out == ''): out = str(i)
print(out)