How to extract particular string from text?

I want to extract 0900821324 from the below text how to do that?


Hi…Is the text is looks like below??

TRN *1* 0900821324*1205693998/

if yes then,

StrText = system.text.regularexpressions.regex.match("TRN *1* 0900821324*1205693998/","\s\d+(?=\*)").value.trim

Here strText is String variable.


Text is like this : -


I used your solution but it’s not working for me, I am getting empty string out of this.

Hi @sambulkar …I just tweaked the code…

StrText = system.text.regularexpressions.regex.match("TRN*1*900821324*1205693998/","\d+(?=\*\d+/)").value


StrText = system.text.regularexpressions.regex.match("TRN*1*900821324*1205693998/","\d+(?=\*\d+\\)").value

Hope this helps…

This should work


No space anywhere

If there is, please advise

The last solution working for me

@sambulkar - Glad to know… Please mark my post as solution , that will close this thread.

Could you please also help, how to extract text before HCCLAIMPMT from below text?

Absolute Total C HCCLAIMPMT 040121 CCD/

you can try like this…

"Absolute Total C HCCLAIMPMT 040121 CCD/".Split(" "c)(3)

here I have to extract any text before HCCLAIMPMT.

here Array is not fix

@sambulkar - I misread your requirement…


Please open up a new forum query in future, if its different from your original query.

This solution is giving empty string

@sambulkar - Please show us what you have tried??

It is working for me…

I applied the same logic, but getting empty string.

currently I am extracting text from below string.

OHANA HEALTH PLA HCCLAIMPMT 040221 100172860653000 CCD/

system.text.regularexpressions.regex.match( OriginalTextCompanyEntryDesc.ToString,".+(?=\s+’"+CompanyEntryDesc.ToString+"’)").value

OriginalTextCompanyEntryDesc - I used this variable to store the actual text.

CompanyEntryDesc - used to store HCCLAIMPMT

@sambulkar - Not sure what exactly you have tried…it is perfectly working for me…

This is the Regex pattern , where you cannot use the dynamic values…

I will have to extract text on dynamic basis

not sure what you mean by dynamic…

if you are always looking for to capture the word before HCCLAIMPMT then your code should be