Regex pattern query

Is there a common way to fetch a key word,its value and dates from the statement below?

Statement:
give all transactions with Type:‘Fee’ and amount<100 and Posted Date between ‘1-Jan-21’ and ‘30-Jun-21’

My desired output from the statment should be a list of strings like
[Type:Fee, amount<100, Posted date between 1-Jan-21 and 30 Jun-21]

Hi,

How about the following expression?

type = System.Text.RegularExpressions.Regex.Match(yourString,"Type\s*:\s*\S+").Value

amount = System.Text.RegularExpressions.Regex.Match(yourString,"amount\S+").Value

posteddate = System.Text.RegularExpressions.Regex.Match(yourString,"Posted Date between.*").Value

Then

{type,amount,posteddate}.ToList()  

1 Like

@shreyaank

You can achieve that using split as well like below

str.Split({"and"},StringSplitOptions.RemoveEmptyEntries,3)

image

cheers

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