LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search for a regular expression in a 1D array?

I've got a 1D array of strings, and I want to find the row with "Date: yy/mm/dd" in it. Since yy/mm/dd would not necessarily be the same between runs, I can't look for the row with "Date: yy/mm/dd".

I tried using the Search 1D Array with "Date: " and "Date: *" as my element input, but it didn't find either of 'em.

I don't know where in vi.lib the function would be in, otherwise I'd attempt to mod the function to take regular expressions, and my off-the-cuff search attempt (looping through the array & using Match Regular Expression) had some odd errors and still didn't find the row.


Thanks!
0 Kudos
Message 1 of 5
(5,227 Views)
Here's one way to do it.  I doubt it's the most efficient, but it works.  You might also try the "Match First String" function, but that'll only give you the first match..


Edit:  After re-reading your post, it looks like "Match First String" may be what you're looking for after all

Message Edited by Day on 09-13-2006 03:02 PM

0 Kudos
Message 2 of 5
(5,226 Views)
What do you define as a "row"? Is each row a single array element? Since your array elements are strings, each array element itself could be a multiline|multirow string itself that might need to be analyzed one row at a time. 😄
 
To look for patterns:
If you have LabVIEW 8.0 or higher, you can use "Match regular expression". Else you can use "Match Pattern". It really depends how specific you need to be. Are there lines that start with "Date:" but don't contain a formatted date afterwards?
 
To search for array elements starting with simple string "Date:", use "match first string".
0 Kudos
Message 3 of 5
(5,219 Views)
Day,

That's somewhat similar to what I had tried to do.

I used Match String rather than Match First String, but I believe either should work (since I'm only interested in one match - "Date: ", the added ability to search multiple patterns at once that comes with Match First String doesn't matter). Since I know the portion of the array the Date will be in (even if I don't know the exact placement), I used a number other than the array size for the loop (~20 rows vs about 50,000 rows). Sort because the For Loop returns an array, and yoink the top one as the rest should be null.

Anyway, that had a type mismatch error going into the For Loop - source as 1D array of strings, sink as 1D array of double.
0 Kudos
Message 4 of 5
(5,209 Views)


@krasing wrote:
Anyway, that had a type mismatch error going into the For Loop - source as 1D array of strings, sink as 1D array of double.


"Index array" wired to [i] is never necessary. Your array is auto indexing already, so you can just wire from the tunnel to the match pattern node. You will get one element at a time per iteration in order.

If you want to use the code as you have it, right-click on the input tunnel and select "disable indexing".

0 Kudos
Message 5 of 5
(5,198 Views)