cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expression

Sree_venkat_rao
Level 2
I would like to write Regex Pattern in BP. My Target string is "TLR - 2234567B,1234543A Some sort of texts" I want to extract numbers ending with letter 'B' or 'A'. So I was used Regex pattern i.e "([0-9]+[A-B])" But I am getting Output as collection with value "Lower" and "Upper". But I need values "2234567B,1234543A"
2 REPLIES 2

david.l.morris
Level 15
Hi Venkat, Try this inputs... Regex Pattern: ""(?([0-9]+[A-B]))[,](?([0-9]+[A-B]))"" Target String: ""TLR - 2234567B,1234543A Some sort of texts"" Named Values: A collection with field names of 'Name' and 'Value'. Add 2 rows (because you want two values). And then in the Name column first row put 'firstValue' without quotes. In the Name column second row put 'secondValue' without quotes. You can leave the Value field blank for both rows. You should create a new blank collection as your output (or pre-create your fields if you want but it's easier if you don't). I've attached a screenshot where I verified it. Hope it works for you. Good luck. =) The thing to learn from this is that you need to name the values you want to get out of the string using ? before the group/value that you get. And then you'll have to note what is between the groups as well. I suppose the other way to do this is to call the Extract Regex Values action twice: the first time would get the first value you want, then you could remove that value from the input and send the input string again. This time it would get the second group/value because the first group has been removed. Also i didn't take much time to verify that the regex pattern above would work for any other similar values or if there were white spaces and such. Respectfully, Dave

Dave Morris, 3Ci at Southern Company

AndreyKudinov
Level 10
You don't actually have to name values, then Name will be numbers: 1,2 for first and second match in this case and 0 will be whole matched substring.  If you need to get unknown number of matches from a string - make your own action or call recursively, like David suggests.