How to extract specific text from a Text file

Hi All,

I have to extract telephone number from a text file. it looks like this
Mobile No. 8 3 7 4 1 7 7 6 45 Tel. No. 25 3 2 607

I am using a regular expression

System.Text.RegularExpressions.Regex.Match(Result,"(?<=(Mobile No. )).*).Value

It is fetching me the entire line. I want to fetch Mobile No and Tel No separately.

Can someone please help

@Lalasa

Kindly Refer this,

Thanks,
Suresh J

Hi @Lalasa
You are using correct method the problem but you are taking entire text Using .* it will give you entire line. and if you try to get the only digit there is space between the every digit. If your Format is Same then use for MO No (?<=Mobile No. )\d\s\d\s\d\s\d\s\d\s\d\s\d\s\d\s\d+ if there is no space then Simply Use (?<=Mobile No. )\d+
Thanks & Regards

Hey,

Use 2 variables to store values of mobile no and telephone no.

please check below-
mobileNo = Result.Substring(Result.IndexOf(“Mobile No.”)+“Mobile No.”.Length).split(Environment.NewLine.TocharArray)(0)

TeleNo= Result.Substring(Result.IndexOf(“Tel. No.”)+“Tel. No.”.Length).split(Environment.NewLine.TocharArray)(0)

Hi, it is popping me up with some expression error.

May be its because of braces misplacement.

Can you suggest the exact format.

@Lalasa

You have to write like this

System.text.regularexpression.regex.match(“yourstring”,regexpattern).value

@Lalasa
Use System.Text.RegularExpressions.Regex.Match(“YourInputString”,“(?<=Mobile No. )\d\s\d\s\d\s\d\s\d\s\d\s\d\s\d\s\d+”)

var1= “Mobile No. 8 3 7 4 1 7 7 6 45 Tel. No. 25 3 2 607”
in assign activity
mobileNo = (Split(Split(var1,“Mobile No.”)(1),“Tel.”)(0)).Replace(" “,”“)
telNo= Split(var1,“Tel. No.”).Last.Replace(” “,”")

could you please check this in workflow.

regards,
Rebakanta

For Mobile number

image

For Tel Number

image

1 Like

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