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


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


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

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


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


@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!

1 Like

ToShareAsTestData.txt (872 Bytes)

Attached is the test data


Thanks for sharing this, I will try and get back


1 Like


No Luck :roll_eyes:

Hi @Ram0803

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

Hope it helps!


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 (42.1 KB)

Omkar P


No Luck bro… :roll_eyes:



Wonderful bro, Worked :+1:



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