Need to to write REGEX

I wanted to get the number 4 from the below image. serviceID = 4 form the above image.Please help me with the Regex.
image

1 Like

HI
i can see like there is one more ServiceID with a numerical value
do we need that also or only the value 4
is there condition or will it remain at same position

or to get that only value
then if the input is in a variable named strinput
-in assign activity like this
stroutput = System.Text.RegularExpressions.Regex.Match(strinput.ToString,“(?<=serviceID = )(\d){1}$”).ToString.Trim

Cheers @Shaik.Yezdani

1 Like

hi
is it ok to use Screen Scrapping / then OCR
Screen Scraping

OUTPUT

@Shaik.Yezdani Please copy+paste the actual text, or upload the .txt file. Otherwise people helping you would have to manually type out the whole text and likely would make mistakes in spacing vs tabs vs newline vs carriage return, etc.

1 Like

Hi @Shaik.Yezdani,

Maybe you can try something like this

In a Matches activity. Pattern serviceID =\W+(?<ID>\d+) or serviceID =\W+(?<ID>\d)\W in case it is always one digit. Save the result into a variables e.g. matches

The value you are looking for will be matches.FirstOrDefault.Groups("ID").ToString

sourceSystemOrderID = 181454044 sourceSystemOrderVersionNo = 1 sourceSystemCD = SLS parentSourceSystemOrderID = 614226841 parentSourceSystemCD = OES orderType = P actionCode = INS eventType = OES_PRTL_SUB_SLS serviceType = creationDt = orderOriginationDt = requestedDueDt = committmentDt = endDt = sourceSystemEventDt = Tue Jan 14 00:00:00 CST 2020 opptyID = variableSection = accountIDList :: serviceIDList :: serviceID = SDP serviceIDType = SYS_ORG_IND serviceID = NORMAL serviceIDType = ORD_HND_MTHD serviceID = 4 serviceIDType = BTLCOUNT serviceID = IQ serviceIDType = ASSIGNEDNM serviceID = 5595219 serviceIDType = SVCCATID errorList ::

did this expression helped us on this
@Shaik.Yezdani

It is giving blank value. I just need 4. Every time format and position will be same.

After serviceID one single digit number will be there.

1 Like

got it
then try with this expression
stroutput = System.Text.RegularExpressions.Regex.Match(strinput.ToString,“(?<=serviceID = )(\d){1}\s”).ToString.Trim

@Shaik.Yezdani

@Shaik.Yezdani thank you for providing the text. Based on the information provided this simple regex should work. Make sure you import System.Text.RegularExpressions

Assign serviceID = Regex.Match(InputText,"(?<=serviceID\s*=\s*)\d+",RegexOptions.IgnoreCase).Value

NOTE: This will return the first match always. It will actually find 2 matches “4” and “5595219”. However you stated that the format and position will be the same so it shouldn’t make a difference.

Superrrrr Thank you so much… it is giving exact output.

1 Like

Have a great day
Cheers @Shaik.Yezdani

1 Like

Do you understand that solution will only work as long as Service ID has only ONE digit right?

You to Great day.

Cheers @Palaniyappan

1 Like

Yes it should always one digit. If not need not to consider.

1 Like

@Palaniyappan If it is having more than single digit then how to deal with this, just now spoke with customer, he told there might be multiple digits but it is always before the serviceIDType = BTLCOUNT Please help me with this.

@Shaik.Yezdani - please see my answer above.

If it is always followed by serviceIDType = BTLCOUNT then you should modify it as follows:

Assign serviceID = Regex.Match(InputText,"(?<=serviceID\s*=\s*)\d+(?=\s*serviceIDType\s*=\s*BTLCOUNT)",RegexOptions.IgnoreCase).Value

Thanks @Dave Have a Great day

Cheers

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