Get part of a text from a string

Hi,

I have a question regarding managing texts. I am getting data from a website in String format that looks like that:

I would like to extract only these part of data as variables:

  • Company Name (i.e. “ROCKY MOUNTAIN CHOCOLATE FACTORY IN (RMCF)”)
    Quote (i.e. 4.21)
    Percentage change (i.e. +0.05 (+1.20%))
    Last Trade Time (i.e. 01/08/2021 10:13:14)

All these information are in the first line. How can I extract it? The name of the company may have different number of characters and words…

Thank you for any advice

Tereza

@Tereza_Steflova - Here you go…

You have to write the Regex groups to get the desired output…

RegexOutputvar(0).groups(1).tostring - CompanyName
RegexOutputvar(0).groups(2).tostring - Quote
etc etc

Please refer this post

Updated Pattern: (?<=QUOTE\s)(\D*)\s([0-9.]+)\s(.[0-9.]+\s(.[0-9.]+.))\s(\D+\d{2}/\d{2}/\d{4}\s\d{2}:\d{2}:\d{2})

5 Likes

Hi, Thank you very much! I am quite struggling to actually get the desired output, how can I write the full expression?

I guess there is a better way earlier to extract the data from the website.

@Tereza_Steflova - Please check this…

image

StrOutput = System.Text.RegularExpressions.Regex.Matches(“QUOTE ROCKY MOUNTAIN CHOCOLATE FACTORY IN (RMCF) 4.21 +0.05 (+1.20%) Last Trade Time: 01/08/2021 10:13:14”,“(?<=QUOTE\s)(\D*)\s([0-9.]+)\s(.[0-9.]+\s(.[0-9.]+.))\s(\D+\d{2}/\d{2}/\d{4}\s\d{2}:\d{2}:\d{2})”)

Write Line: "Match is: " +VBcr+ StrOutput(0).groups(1).ToString+VBcr+ StrOutput(0).groups(2).ToString+VBcr+ StrOutput(0).groups(3).ToString+VBcr+ StrOutput(0).groups(4).ToString

Output:
Match is:
ROCKY MOUNTAIN CHOCOLATE FACTORY IN (RMCF)
4.21
+0.05 (+1.20%)
Last Trade Time: 01/08/2021 10:13:14


StrOutput(0).groups(1).ToString = ROCKY MOUNTAIN CHOCOLATE FACTORY IN (RMCF)
StrOutput(0).groups(2).ToString = 4.21
StrOutput(0).groups(1).ToString = +0.05 (+1.20%)
StrOutput(0).groups(1).ToString = Last Trade Time: 01/08/2021 10:13:14

Thank you, I have meantime found the solution :slight_smile: