Hi,
How do i get string between two string(“for”).
For ex.:- “Outstanding Bill for xyz company for Mar 20”
expected output: xyz
But sometime company name contain
So basically i want complete string between first “for” and last “for”.
Please Suggest
Gokul001
(Gokul Balaji)
2
Hi @TUSHAR_DIWASE
Use Assign activity
LHS - Create an variable
RHS - System.Text.RegularExpressions.Regex.match(InputString, “(?<=Outstanding\sBill\sfor\s)(\S+)”).Tostring
Regards
Gokul
Hi @TUSHAR_DIWASE ,
Is the keyword company always present?
If so, then this ought to work:

System.Text.RegularExpressions.Regex.Match(str_variable,"[^\s]+(?=\scompany)").Value
Kind Regards,
Ashwin A.K
@ashwin.ashok thanks but “Outstanding Bill” and both “for” word are constant.
so i want string between first and last “for”
Gokul001
(Gokul Balaji)
5
HI @TUSHAR_DIWASE
Try this expression
Use Assign activity
LHS - Create an variable
RHS - System.Text.RegularExpressions.Regex.match(InputString,“(?s)for(.*?) for”).Groups(1)
Regards
Gokul
1 Like
@Gokul001 an you please assist me about the LHS type of variable
Hi @TUSHAR_DIWASE ,
Is this what you meant?


System.Text.RegularExpressions.Regex.Match(str_variable,"(?<=for\s)(.*)(?:\s.*)(?=\sfor)").Groups(1)
Kind Regards
Ashwin A.K
1 Like
@Gokul001 string is not accepting variable type
Gokul001
(Gokul Balaji)
11
HI @TUSHAR_DIWASE
Try this expression
System.Text.RegularExpressions.Regex.Match("for is for","(?s)for(.*?) for").Groups(1).ToString
Regards
Gokul
Gokul001
(Gokul Balaji)
12
End of the expression after Groups(1) just give the .Tostring
Regards
Gokul
1 Like
You can use the below regex for getting the data previous to fixed variable
**
[^\s]+(?=\scompany)
**
Use this regex syntax to get the data between two labels/fixed variables
**
(?<=for).*(?=for)
**
system
(system)
Closed
14
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.