How Extract String

Hi ,
I have the below string:

  • Home 022-024272-701
  • TAIEF Ibraheem 465234N01T8A
  • Home 742419F55CT1

I need to peek what before Number For example :

  • Home
  • TAIEF Ibraheem
  • Home

Could anyone share a regex or any other way of getting this Please .

Thanks .

Hi @Teaf ,

Based on the Inputs you have provided, there seems to be a Space before a Number and the data before the Space constitutes to your Required Data to be extracted.

Keeping this mind, I think you can test with the below Expression :

(.*)\s\d

(.*) is your required data, which in the Expression is a Group. Hence, You would need to get the First Group from the Result Match in the below way.

System.Text.RegularExpressions.Regex.Match(InputStr,"(.*)\s\d").Groups(1).ToString.Trim

InputStr is the Input data variable

Let us know if this Expression doesn’t work for all your Test Data.

3 Likes

Thanks for your response.

Unfortunately doesn’t work for all data such as TAIEF Ibraheem 465234N01T8A

That is Strange, It does seem to be working on my end. Please let us know what is the exact input data that you have provided.

@Teaf You can Check the below Image of Extracted data.

Exact input :

TAIEF AL BAHUSSAIN 465234N01T8A AL RAJHI BANKING AND INV T CORP BR 192 JEDDAH EX Rate : SAR 1.0000000 AL RAJHI BANKING AND INV T CORP

Another Example :

CHARGES SAR 10.00 267128V1267A BANK AL BILAD TOTAL VAT SAR1,05 ON CHARGE AMOUNT SAR10,

I need to peek :

  • TAIEF AL BAHUSSAIN
  • CHARGES

Hi @Teaf ,
Use Below pattern and take only first occurrence
.*?([0-9])

Regards,
Arivu

1 Like

HI @Teaf

Try with the below Expression
\S.+(?=\s\d)

Regards
Sudharsan

doesn’t work. The output :

  • TAIEF AL BAHUSSAIN 4
  • CHARGES SAR 10

Hi @Teaf ,
Try below Regex pattern
^\S.+?(?=\s\d)

Regards,
Arivu

Hi @Teaf

Can you try out this expression

((?<=\w\s)(\d+|\d)[\-\w]+)

Thanks
Robin

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.