Hi all,
I’ve email body as string with me
e.g.,
Application: Netflix
Account : XYZ
Operation: Remove
Attribute: Access Rights
Value: Write
Application: Netflix
Account : XYZ
Operation: Disable
I want only below mentioned part of the string
Application: Netflix
Account : XYZ
Operation: Disable
arivu96
(Arivazhagan A)
March 27, 2025, 6:31am
2
Harsha_Joshi:
Application: Netflix
Account : XYZ
Operation: Remove
Attribute: Access Rights
Value: Write
Application: Netflix
Account : XYZ
Operation: Disable
I want only below mentioned part of the string
Application: Netflix
Account : XYZ
Operation: Disable
Below are the regex pattern to extract the value
(?<=Application: ).*
(?<=Account: ).*
(?<=Operation: ).*
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
Use Assign activity
strApplication=System.Text.RegularExpressions.Regex.Matches(inputString, "(?<=Application: ).*")
strAccount=System.Text.RegularExpressions.Regex.Matches(inputString, "(?<=Account: ).*")
strOperation=System.Text.RegularExpressions.Regex.Matches(inputString, "(?<=Operation: ).*")
Regards,
Arivu
If the idea is to extract the 3 repeating rows which contains keyword Application, Account and Operation - you can use below pattern
Application:\s*\w+\sAccount\s :\s*\w+\sOperation:\s \w+
Note: It should come in the same same order
Hi @Harsha_Joshi
Welcome to the Community.
Here is one approach.
Regex:
LLM was used to generate the Regex only
"(?s)Application:\s*(?<Application>.*?)\s*Account\s*:\s*(?<Account>.*?)\s*Operation:\s*(?<Operation>.*?)(?:\s*Attribute:|$)"
It will give 2 matches with 3 groups each
The Output you want, will be in Match 2.
The Implementation:
Extract as individual Groups from second Match.
application = System.Text.RegularExpressions.Regex.Matches(inputString, "(?s)Application:\s*(?<Application>.*?)\s*Account\s*:\s*(?<Account>.*?)\s*Operation:\s*(?<Operation>.*?)(?:\s*Attribute:|$)")(1).Groups("Application").Value
account = System.Text.RegularExpressions.Regex.Matches(inputString, "(?s)Application:\s*(?<Application>.*?)\s*Account\s*:\s*(?<Account>.*?)\s*Operation:\s*(?<Operation>.*?)(?:\s*Attribute:|$)")(1).Groups("Account").Value
operation = System.Text.RegularExpressions.Regex.Matches(inputString, "(?s)Application:\s*(?<Application>.*?)\s*Account\s*:\s*(?<Account>.*?)\s*Operation:\s*(?<Operation>.*?)(?:\s*Attribute:|$)")(1).Groups("Operation").Value
Or
Extract the entire Match
match = System.Text.RegularExpressions.Regex.Matches(inputString, "(?s)Application:\s*(?<Application>.*?)\s*Account\s*:\s*(?<Account>.*?)\s*Operation:\s*(?<Operation>.*?)(?:\s*Attribute:|$)")(1).Value
The Output
If you extract individual Groups:
If you extract entire match:
If this solves your query, Do mark it as a solution
Happy Automation
singh_sumit
(Sumit Singh Tariyal)
March 27, 2025, 6:42am
5
Hey @Harsha_Joshi could you try this method
this will give to the exact value from the string input for most value just modify the inside pattern value from Account to Application or operation
cheers
Hey
I used the second approach of extracting entire match.
Thanks for you help
1 Like
Good to know.
Do mark it as a solution and close the thread.
Happy automation
system
(system)
Closed
March 30, 2025, 7:15am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.