Nancy29
(Dropoffhoney29)
March 5, 2024, 11:17am
1
Hi Team,
Please help in getting the second word (dynamic word which varies in each run) in a line using regex match.
eg: 00100100000 W123456789 254721 AQQW S
I need second word: W123456789
I used this formula [0-9A-Za-z]{3}\d{7} and getting the first word :00100100000
please help.
Thanks
mkankatala
(Mahesh Kankatala)
March 5, 2024, 11:19am
2
Hi @Nancy29
You can use the below one,
[A-Z]\d+
- Assign -> Input = "00100100000 W123456789 254721 AQQW S"
- Assign -> Output = System.Text.RegularExpressions.Regex.Match(Input.toString,"[A-Z]\d+").Value
Check the below workflow,
Hope it helps!!
1 Like
Hi @Nancy29
Try this is Assign Activity
System.Text.RegularExpressions.Regex.Match("00100100000 W123456789 254721 AQQW S","(?<=\s)\S+").Value
Hope it will helps you
Cheers!!
Nancy29
(Dropoffhoney29)
March 5, 2024, 11:26am
4
hi @mkankatala
Thanks for your quick help. Will try it now.
Also can you please give the formula for getting the fourth word (AQQW) as well
Thanks
Nancy29
(Dropoffhoney29)
March 5, 2024, 11:28am
5
Hi @Nawazish_Ahmad
Sure. Thanks for your quick help. Will try this as well.
1 Like
mkankatala
(Mahesh Kankatala)
March 5, 2024, 11:28am
6
Okay @Nancy29
You can use the below one,
[A-Z]{4}
Hope it helps!!
1 Like
pikorpa
(Piotr Kołakowski)
March 5, 2024, 11:29am
7
Hey @Nancy29
you can use:
^\S+\s+(\S+)
secondWord = System.Text.RegularExpressions.Regex.Match(yourInputString, "^\S+\s+(\S+)").Groups(1).Value
mkankatala
(Mahesh Kankatala)
March 5, 2024, 11:30am
9
It’s my pleasure… @Nancy29
I hope you find the solution for your query, If yes Make my post mark as solution to close the loop.
Happy Automation!!
1 Like
Nancy29
(Dropoffhoney29)
March 5, 2024, 11:31am
10
Thanks a lot. Will try it.
Instead of using match, use matches on any word character \S+
The result is a collection, of which you want the 2nd item. This is much more flexible than the above solutions if you ever need to switch to the 3rd, 4th etc. word.
reference: https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.matches?view=net-8.0
System.Text.RegularExpressions.Regex.Matches("Koe Schaap Konijn", "\S+")(1).ToString
(…and for the non-Dutch speaking people here, the words are Cow, Sheep and Rabbit )
system
(system)
Closed
March 8, 2024, 12:30pm
13
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.