Regex to fetch required yellow highlighted value

Hi Guys
Hope you are doing well I have one MS Word file which come from e mail attachment and my task here to open that file and using get full text activity
scrape complete data from that file after that search “Sd_Linkdigital_DeviceType:” and fetch look behind the value like desktop in given screen shot the problem is here I am getting file too long error
My regex is (?<=Sd_linkdigital_devicetype:).* I already paste raw data in below with screen shot please help me with correct regex so that I only get “Desktop” or any value after Sd_linkdigital_devicetype:

Q064 - Sd_linkdigital_contexttype: Youtube
Q065 - Sd_linkdigital_format: Video
Q066 - Sd_linkdigital_devicetype: Desktop
End B014 - Kapconfig: Placeholder for study level metadata settings
Q056 - Newsfeedquota: Quota on Newsfeed
Q057 - Stoplook_watchskip: Stoplook_watchskip
End B001 - Startlinkexpressdigital_module: Startlinkexpressdigital_module
B002 - Kantarscreenerlinkexpressdigital_module: Kantarscreenerlinkexpressdigital_module
Q001 - Introduction: Introduction
Q002 - Avquality: Avquality
Q003 - Avmessage: Avmessage
Q004 - Adname: Adname
Q005 - Seevideo: SeeVideo
Q006 - Hearvideo: Hearvideo
Q007 - Occupation_scr: Occupational screener
Q008 - Age: Age
Q009 - Agerefusal:
Q010 - Agequota: Agequota
Q011 - Sex: Gender

Hi @Aleem_Khan

Whether the values before the highlighted text is constant?

Regards
Sudharsan

If yes you can try this regex
(?<=_devicetype:\s)\S+

Regards
Sudharsan

no some time this value come up and sometime come down
but Sd_Linkdigital_DeviceType: will exist in somewhere in whole file.

So do you have any constant value in the above line or below the line of Sd_Linkdigital_DeviceType:?

can we try like this!

(?<=Sd_linkdigital_devicetype:\s).*

Regards,
NaNi

You can also do one thing if the highlighted value will be always the first match means you can give the regex with matches and give the index as 0

Regards
Sudharsan

Not working same error file to long error and other value is also come with that please check screenshot

you can use like this System.Text.RegularExpressions.Regex.Matches(“String”,“(?<=_devicetype:\s)\S+”,RegexOptions.IgnoreCase)(0).ToString

or
System.Text.RegularExpressions.Regex.Match(“String”,“(?<=_devicetype:\s)\S+”,RegexOptions.IgnoreCase).ToString

Regards
Sudharsan

3 Likes

Thank you so much it is working can you please explain this to improve my learning knowledge what is use of RegexOptions.IgnoreCase and full expression

Yeah sure if you use matches activity

you will choose options, right?

Like that we are using directly in an expression

And what it will do:
- as named it will simply ignore the case and search for the exact word you are using
by default, regex is case sensitive by giving this option it will search the exact word which is in capital or small

Hope this helps

Regards
Sudharsan

1 Like

HI @Aleem_Khan

Kindly mark the appropriate post as a solution so that it will be helpful for others too

Thanks and Happy Automation

Regards
Sudharsan

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