I want to check only starting words matching with keywords

Hi,
I want to check if starting words matching with keywords or not if matched then return keyword value.
Note: keywords are not fixed and more than 60 keywords are there and more will be added in future.

Sample Keywords
Paytm
Phonepe
Google Pay
Amazon pay later

Example 1.
String input:
“Paytm transaction of 6788 rs received”
Output:
Paytm

Example 2
String input:
“Received transaction from other party Phonepe through external”

Output:
No output
Note: we want only starting word

Example 3
String input:
“Received Google Pay transaction from XYZ company”
Output:
No output
Note: we need to check starting words here Received word is starting word not Google.

Example 4
String input:
“Amazon pay later transaction received from xyz user”
Output:
Amazon pay later

1 Like

Hey @Mansi_Mhatre

  • Have the keyword list either in Asset or Config. This will help keep things dynamic like you can add or remove keywords

Keywords will be used as comma separated or any other delimiter as required

  • Read the Asset or Config value as a string comma separated

  • Split the string using delimiter and convert it to array

  • Use foreach to iterate through this array of keyword strings to check the actual input string to verify whether it starts with the keyword

String.Startswith is a good option

  • If you find a match then save the keyword in the output string variable & break the loop

Hope this psuedo logic helps you.

Thanks
#nK

Hi @Mansi_Mhatre ,

As per the requirement we could use small logic of string manipulation and switch case achieve this.

  1. Use yourstring.split(" "c)(0).tostring
    Get you thr first word after splitting. And assign this expression to one variable StringKeyword

  2. Use switch case

Case1 → StringKeyWord = “Paytm”
Case2 → StringKeyWord = “Phonepe”
Case3 → StringKeyWord = “Google”
Case4 → StringKeyWord = “Amazon”
Default ->No output

Sharing my thought. Please try and let us know. Thanks.

Sry…
As mentioned we have more than 60 keywords and more can be added in future also keywords can be two words like Amazon pay later or Sahara Internet.

Ok got your point. In that case pls try the suggestion from nitin @Nithinkrishna

1 Like

Hi,

We can achieve this using regex as the following.

result = System.Text.RegularExpressions.Regex.Match(yourString,"^("+String.Join("|",arrKeywords.Select(Function(s) System.Text.RegularExpressions.Regex.Escape(s)))+")").Value

Regards,

Also how to find starting 4-5 words from given string using regex.

Hi,

Also how to find starting 4-5 words from given string using regex.

It works by the above expression. Can you try this?

Regards,

For some keywords other word is occurring at the start of the string and those words are not fixed so want to build logic with the help of staring 4-5 words check.

Hi,

Can you give us some examples?

Regards,

Example 1.
String input:
“Returnpay Paytm transaction of 6788 rs received”
Output:
Returnpay Paytm transaction of

Example 2
String input:
“Received transaction from other party Phonepe through external”

OUTPUT:
Received transaction from other

After extracting 4 words want this result…

Hi,

how about the following?

String.Join(" ",yourString.Split(" "c).Take(4))

OR

System.Text.RegularExpressions.Regex.Match(yourString,"^(\S+\s*){1,4}").Value.Trim

Regards,

1 Like