Matches activity: can't match my target text

Hi, I am using Matches activity to extract a 6-digit postal code from a string.
image
The RegEx expression I am using is \d{6}:
image
However, the result it generated is 48623, the first digit 0 is missing.
image
Please help me with this. Thank you!

it think it correctly extracted 048623 but when you write to excel it removed the leading 0 because of formatting issues.

To fix this you can manually convert column format (column S in your case) to “text” format before you write to excel

before you write to that excel, open the excel manually and then:

1- highlight column S, go to Data-> Text to columns
note: (column S must have at least 1 non-empty cell before you can click “text to columns”)

  1. keep pressing next until this page, when in this page, click “Text” then click finish

  2. highlight column S, right click and click format cells
    image

  3. choose text
    image

  4. next time you write to this excel it should correctly have a 0 in front

1 Like

Hi @YwOli,

You can fetch it using below assign activity

strOutput=System.Text.RegularExpressions.Regex.Match(your input string,"\d{6}").ToString

I have attached the sample file for your reference. Hope this helps :slight_smile:

test_02.xaml (4.6 KB)

yes, you are right! it works after I change the cell format to text. Thank you.

Hi @sai_krishnaji_Gujjaru, I tried your method but the first 0 is still missing when it is inputted in Excel, so I went to change the cell format and the issue is solved. Thank you very much!

No problem, please mark my reply as solution

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