I wish to extract certain string based on fixed pattern of the input String I am providing and for this I am using Matches activity of Uipath. The problem I am facing is while extracting data from multiple lines. My Input String looks like below:
28 - Country - Germany (DE)
83 - Location - F 709, Ludwigshafen, Germany
448 - Building - F 709
449 - Floor - EG
450 - Room - 3
461 - Remark / Comment - Example Text
519 - Number of LAN ports -
723 - Wall outlet number - Example Number
1046 - Patch removal -
1047 - GSP Message ID - Port_Patching
1122 - Aftercare - Aftercare
Expression before “-” is the fixed pattern for all lines, like in "448 - Building - " left site expression is fixed. If I wish to extract only one line, Matches is working fine with Pattern “448 - Building - (.*)” but if I want to extract data from more lines, it fails.
can anyone suggest how can I use multiple patterns to extract multiple expressions.
Fine
keep this whole string in a text file
–now use read text file activity and get the output with a variable of type string named str_input
–now use a assign activity like this arr_strings = str_input.Split(Environment.Newline.ToArray())
where arr_strings is a variable of type array of string
–now use a FOR EACH ACTIVITY and pass the above variable arr_Strings as iinput and change the type argument as string in the property panel
–inside the loop use WRITELINE activity with this expression Split(item.ToString,“-”).last.ToString.Trim
I used similar Regex “\d+\s-\s(?:.* - )(.*)” and it is working fine. I think it will work in match, I will test this, can you suggest how Output of Match seems like ?
Fine
Mention this in MATCHES activity and get the output with a variable named out_matches and enable multilingual option as @Yoichi suggested
—now use a FOR EACH activity and pass the above variable as input and change the type argument as System.Text.RegularExpressions.Regex.Match in the property panel of for each loop
—inside the loop use a writeline activity and mention like this item.ToString
true, it is working for some expressions but not for all, I think I need to explore more patterns to get exact match for complete string, though multiline option helped.
Specifically, you could use something like this if you’re sure that the input is going to always be in that format where there’s a number, hyphen, thing, hyphen, thing you want captured:
I am using the same thing, but its the position i think not able to understand. Could you suggest if this is the community edition you are using in the screenshot ?
When dealing with regular expressions, you should use a tester first to make sure that the Regex applies to your data. In the example I posted, I used .NET Regex Tester - Regex Storm, which is advisable as it uses the .NET language Regex.
The Pattern which we were using was incorrect thus it was not showing the correct value. This this Regex Tester I could finally locate the position and extract the elements.