RegEx in arrays

by P. Andreas Schmidt, IVE

Version 3 (May 4, 2022)

Download (29 downloads)

Update: fixed block 176 to be device/copy independent. Sorry about that

This is a flow I want to share after my own struggles of finding out how to regex in an array (and finding the index to that element)... thanks also to Ricardo's flow for giving me some input and help ( Unfortunately, the help documentation isn't clear enough about some functions e.g. findAll also working on arrays. All the same it doesn't work the same way as matches, for example. Matches will work on each element separately, but it doesn't give you the option to search starting from certain index, which can be overcome by slicing your array... findAll will (apparently) join all elements into a string that are comma "," separated. Knowing this, if you're searching to get the whole element to match (as matches does, and what you need for indexOf to find it in the array) and not just a part, you can't do as with matches (and as the documentation states) and put in between ".*"s, but instead (this is not stated had to figure it out...) "[^\s,][^,]*...[^,]*" (else you'll end up with a one element array with that string of comma separated elements joined........ -.-)
This last solution is fine but will not work if your text you want to match includes ","s... So for this you'll have to join your array with another delimiter (e.g. "|") and then you can either sort of "manually" got through it by indexOf the next occurrence, count the delimiters up to that point (findAll), and you get the index in your array of that element, and so on. Or use the findAll method again but now escaping the delimiter.
In this flow I use as an example an array of task lists assigned to different people and you only want to find the indexes of those assigned to a certain person. This is especially necessary if you have corresponding arrays so you don't just want the titles of the tasks but need the index for the other arrays with corresponding data. There are three different choices for each solution I've given here. It will also tell you how much time passed, there isn't a great difference.
Hope this will help others.
Other solutions, comments, problems, suggestions very welcome!

4.0 average rating from 2 reviews

5 stars
4 stars
3 stars
2 stars
1 star

Rate and review within the app in the Community section.