07-19-2021 06:28 AM
I have a text file as an input string containing 2 columns of date and equation separated by a tab.
Now I want to read that file and search for a specific equation like x^10+5 and replace it with something, so my search string looks like this:
19-07-2021\t3x^10+5\n
this works fine if I search it without using regular expressions but this will only work for a specific date and I want to make it any general date, so I tried:
[0-9]+-[0-9]+[0-9]+\t3x^10+5\n
but this is not giving the result(in fact it is not giving me any result) that I want because of the "^" symbol.
So please help me in searching 3x^10+5 using regular expression.
I hope that I was able to explain my problem properly. Please let me know if something is still not clear.
Thanks in advance
Best regards
Ankit Yadav
Solved! Go to Solution.
07-19-2021 06:44 AM - edited 07-19-2021 06:45 AM
Escape it with a \.
Special characters (., [, (, *, +, $, ^, ], ), \, {, }, |, perhaps others) (often) needs escaping.
07-19-2021 06:48 AM
According to manuals found in the internet I'd try
\xhh
where hh is replaced by the hexcode for the circumflex sign.
Regards, Jens
07-19-2021 06:50 AM
Note that the help mentions that LabVIEW uses the PCRE library.
So, most online information on that library can be used for LabVIEW regular expressions
But some dialects aside, googling "regular expression ...", for example "regular expression capturing groups", will very often give usable results.
07-19-2021 06:51 AM
@JensG69 wrote:
According to manuals found in the internet I'd try
\xhh
where hh is replaced by the hexcode for the circumflex sign.
Regards, Jens
Simply \^ should work.
07-19-2021 07:04 AM - edited 07-19-2021 07:05 AM
You need to use '\' before any special characters. So you need to add it before the '^' and the '+'.
07-19-2021 07:19 AM
Thanks, everyone for your quick responses.
I tried this:
and as you can see, \^ didn't work without using \+ as crossrulz mentioned. Thanks for it crossrulz.
Thanks, Jens for letting me know something like \x5E, it worked(somewhat) and replaced the ^ symbol only. Like:
as you can see it didn't work if I search for \x5E+5( I don't know what I should input in the search string to replace the whole equation😞).
Best regards,
Ankit Yadav
07-19-2021 07:27 AM - edited 07-19-2021 07:30 AM
@yadavankit9999 wrote:
Thanks, everyone for your quick responses.
I tried this:
and as you can see, \^ didn't work without using \+ as crossrulz mentioned. Thanks for it crossrulz.
Thanks, Jens for letting me know something like \x5E, it worked(somewhat) and replaced the ^ symbol only. Like:
as you can see it didn't work if I search for \x5E+5( I don't know what I should input in the search string to replace the whole equation😞).
Best regards,
Ankit Yadav
You need to escape all special characters (as mentioned in the 1st reply).
So you also need to escape the +. "E+" matches one or more "E". "E\+" matches "E+".
To add to the mix, you can also use \136, where 136 is the octal value for ^.
Your expression "\x5E5+5" matches "^55", "^555", and so on.
Use "\x5E5\+5"