How to get the single occurrence of a string using RegEx

Dear All,

I have a scenario, where in i want to read a pdf —> write the pdf content into a textfile —> read the text file —> get the required values which which has occurred only once

Eg: I my text file, i got something like Mobile Number 88888888888 using regex editor, i managed to get the Mobile Number value,but the problem is, the same content i.e “Mobile Number 88888888888” is repeated thrice in the text file, as a result,i am getting the same value repeated thrice, but, i wanted to get only once (first occurrence)

Please help me with the correct RegEx,so that i can implement the same

Regards,
Ram

@Ram0803 Is only one mobile number present in pdf file but mulitple times? or something different scenario

@Manjuts90

No, there are totally 3 times, the same Mobile Number 88888888 is getting reprted…

Eg:
The same text “Mobile Number 88888888” is present in second line, 7’th line and 9’th line of the txt document.

Hence after executing the regex, i am seeing the same value (i.e.Mobile Number 88888888) printed three times,instead, i just want to get it printed only one time

@Ram0803 Try below regex pattern with match method

       "(?<=Mobile Number[\s]+)[\d]+"

If you are already getting required value then use ur pattern with match method or try above one

@Manjuts90

Sorry, i tried with this,but no luck with this

Cheers!!
Ram

@Ram0803 If possible can you provide sample pdf sample?

hey buddy @Ram0803

  • if you are using Matches activity, do like this for example let us imagine you got the output of Matches as outMobileNumber

  • if you want first occurrence you can simple use outMobileNumber(0).ToString in Message Box
    to get the first Mobile Number

Let me know if this worked for you!
Cheers
@Ram0803

1 Like

ToShareAsTestData.txt (872 Bytes)

Attached is the test data

@Pradeep_Shiv,

Thanks for sharing this, I will try and get back

Cheers

1 Like

Cheers
@Ram0803

No Luck :roll_eyes:

Hi @Ram0803

Can you try this regex ([Mobile Number\d]+)

Hope it helps!

@Ram0803,

Pls try attached solution and let me know if you have any issues.

output(0).Value -->1 num will display
output(1).Value–>2 num will display
output(2).Value–>3 num will display(as per your input last number "Mobile number after dot having so in that case error will through)change as per your req

New folder.zip (42.1 KB)

Regards,
Omkar P

@harshit_singh,

No Luck bro… :roll_eyes:

Cheers!
Ram

@Reddy_Paluri

Wonderful bro, Worked :+1:

Thanks

Cheers!
Ram

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