Help with Regex statement

Hi. I have a Regex Command as follows that looks for "Title: " and then extracts the text afterwards. My current command only gets the first word, however I would like to get the rest of the line as the title may be multiple words. I have also included a secondary expression which worked when I tested in on regex101 however when it runs it gets all text after the "Title: " which includes the rest of the original extracted text.

Is there a command that goes up to the next Line Feed / Carriage Return?

My other option is to extract test after "Title: " and before "Attention: ".

Any thoughts on what is the better option? Also, not sure how to do Option 2.

Thanks

Craig…

Sample Text
Title: Consultation Title Goes Here
Attention:
Summary
<A brief description of what is out for Consultation

Current expression
(?<=Title:\s)(.*?(?=\s))

Secondary expression
(?<=Title:\s)(.*)

Hi,

Your expression seems no problem. Isn’t the following what you expect?

image

Regards,

Hi @Yoichi . That is exactly what I’m wanting to extract, however when I run this in Studio it continues to extract all text after the parts that are highlighted “Consultation Title Goes Here”.

HI,

Can you share your input string as a file, if possible?
We can write it to a file using WriteTextFile activity.

Regards,

Your secondary expression should be working. Could you check if you happen to have the “Singleline” option checked? Based on what you’re describing it appears that that option is currently enabled, resulting in all text in all lines being captured, as opposed to stopping at new line.

image

Hi @Yoichi . This is a cut-down version of the output that came from my original file and it used as the input for the regex command.
output.txt (584 Bytes)

Hi @yikwen.goo . The Singleline option is turned off. The only enabled options are IgnoreCase and Complied.

Hi,

Thank you for sharing. This txt file’s linebreak is CR (0x0D) (Old Mac style linebreak). So we need to use the following pattern, for example. Can you try this?

System.Text.RegularExpressions.Regex.Match(strData,"(?<=Title:\s).*?(?=[\r\n])").Value

Regards,

2 Likes

Hi @Yoichi . That works perfectly. Thank you so much.

1 Like

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