04-25-2025 06:25 PM
I am using LabVIEW 2019 on Windows 10 and Windows 11 systems.
I want to use a regular expression to find & replace trailing 0's in a csv file.
I want to do this for my tab (`\t`) delimitered, CRLF EOL'd (`\r\n`) file.
I want to be able to have my regex accomplish this in one pass, but I can't figure out the syntax to reference a capture group.
I can accomplish this in 2 passes (top example) but this is inefficient for a ~20k line file.
My concern is that LabVIEW (or at least my version) does not support this feature.
I am able to do this with python:
....but I am not able to figure out how to do it in LabVIEW -- which is where the codebase I need to implement this in actually lives.
Does anyone know how to do this?
I have search the NI forums, and searched the internet more broadly for help with this, but no luck yet.
Please let me know if I can/should provide more details.
And thank you in advance.
Solved! Go to Solution.
04-25-2025 07:18 PM
This is from the help file for "Special Characters for Match Regular Expression and Search and Replace String":
When you use the Search and Replace String function in Regular Expression mode, you can specify a backreference in the replace string input that refers to submatches in the search string input. Use $1 to refer to the first submatch, $2 to refer to the second submatch, and so on. You can use these special characters only in the replace string input of the Search and Replace String function. Use these special characters to insert a string you specify before or after the submatch you specify. Consider the following example:
input string: $value "TRUE"TRUE" *NULL
search string: (["*$])(\w+)\1\2\1
replace string: $1$2value$1
result string: $value "TRUEvalue" *NULL
In this example, the $1 backreferences in replace string refer to the first submatch in search string. Likewise, the $2 backreference refers to the second submatch in search string.
I think this is what you are asking about, but I am not 100% sure and since you didn't post your example code as a VI I can't try it without replicating it myself, which I am not going to do....
04-28-2025 10:42 AM
This did exactly what I needed, thank you!
(I just re-checkedd my help file for Search and Replace String Function, but I do not find a link to this secondary help file.)