cancel
Showing results for 
Search instead for 
Did you mean: 

Regex pattern

VratHimbo
Level 6

Hi all,
i've a collection field with dynamic column name but always with ONE row.
I need to check if this row contains at least one "YES" value.
I didn't want to loop through each collection, so my idea is to use:
1) Get collection as CSV (in that case i have one text data item with all values separated by a comma) but now, how can i check if at least one value after comma (,) is YES?
Can i use a regex pattern?

Thanks in advance



------------------------------
Vrat Himbo
------------------------------
10 REPLIES 10

HarshitRawat
Level 8
I think you can use the below  Action under Collection Manipulation
28313.pngYou can put collection name, column name and exact value you wish to search. and there is a flag output which would provide the result if the value exists inside the collection




------------------------------
Harshit Rawat
------------------------------

Thanks @Harshit Rawat,
unfortunately, i haven't the same column name, only the values and first row are fixed.
Like this:
Column1?? Column2?? Column3?? Column4??
YES              NO              YES             NO

And i need to check if at least one value of the first row is yes. I don't want to use a loop, so i've tried to convert collection to CSV (text) but i don't know how can i check it, with regex or in other way​

------------------------------
Vrat Himbo
------------------------------

NicholasZejdlik
Level 9
This should suffice as a regex pattern: \s{0,}\"{0,}YES\"{0,}(,|$)

It ensures the entire cell content is YES, so "YESTERDAY" wouldn't match, and it also discards any leading spaces or if it is surrounded by quotation marks that some CSV formats will throw in there. Keep in mind it'll match if a column is called "YES" as well, so it might be wise to trim the header line off before running this.

Personally, I'd shoot for a more reusable option; you could create an action that takes a collection and searches for any values. With a code stage you'd be able to iterate over all of the fields in the collection and make sure it's a proper match as opposed to a regex search.

------------------------------
Nicholas Zejdlik
RPA Developer
------------------------------

Hi Vrat,
As you said you have taken the text into a data item please share your thoughts for the below approach
28321.png
​The data item contains the text separated by ",". I am just checking if either ",YES" or "YES," are present in the data item . IF the Decision yields Yes this means the text data item contains your value.
@VratHimbo

------------------------------
Harshit Rawat
------------------------------

Thanks for your solution.
The only problem is if i have a column with the name starts with YES.
For example Column1??,YES+*Column2,NO,NO,NO

------------------------------
Vrat Himbo
------------------------------

Thank you, i've tested the regex but in this case it match also with a column name that contains YES, is correct?
I can do it in C#? Do you know if there is something already done?
Is possible to use a LinQ Expression to check it?


Thanks in advance



------------------------------
Vrat Himbo
------------------------------

Can use C# and Linq. If you use Linq in a code stage, make sure to add a reference to System.Linq.dll and the System.Linq namespace in the global object code. Since collections are a DataTable in a code stage, you'll have to call AsEnumerable() on it to be able to use it in a Linq expression, for example:

found = table.AsEnumerable().Any(row => {
	foreach (DataColumn col in table.Columns) {
		if (row[col].ToString() == valueToFind) {
			return true;
		}
	}
	return false;
});​


------------------------------
Nicholas Zejdlik
RPA Developer
------------------------------

Thanks for the reply.
I put in input Datatable & ValueToFInd (text), a boolean in output, imported System.Linq.dll and the System.Linq. And i've imported system.data.datasetextensions. But i've this problem. How can i fix it? Thanks
28325.png


------------------------------
Vrat Himbo
------------------------------

I've imported System.core.dll and now it seems to work, is that correct? @Nicholas Zejdlik

------------------------------
Vrat Himbo
------------------------------