Regular Expressions with Asset

Hi Team,
I have a regx code like
System.Text.RegularExpressions.Regex.Replace(SourceName,“^(THE|AND|)+”,“”)

The above code will remove the words THE & AND in a beginning of a line. it works fine.

Now i have a asset say (ExcemptKeywords) which has the words THE, AND, WAS… will be access these in a loop. My question is How to get this ExcemptKeywords asset variable inside this regx i tried like below but not working. Kindly help me to modify the below code.
System.Text.RegularExpressions.Regex.Replace(SourceName,“^(item.tostring)+”,“”)

Hi @Balan

Is the words THE, AND, WAS was in array or excel where did you get this data from…

thanks

Words (THE, AND, WAS) is coming from asset these values will be added using comma.
Using for loop reading the asset (item).
In the code below how to remove THE|AND… and place this item.tostring?
System.Text.RegularExpressions.Regex.Replace(SourceName,“^(THE|AND|)+”,“”)

@Balan

Please try this

assume strText is the value you are getting from asset

System.Text.RegularExpressions.Regex.Replace(“test”,“^(”+string.Join(“|”,strText.Split(“,“c))+”)+”,“”)

image

@Balan,

Can you try with below code, i did not use asset instead i stored values in string,
then I retrieved THE AND from string using substring and stored in variables.

and last i appended those variables in pattern.
image

@Prasanth. Just explaining how i am using ur code. Confirm its right.
I am getting these asset values in - for loop.
Inside loop i have added your code.
In Test1 variable contains = “AND TESTING IN TEST”
ystem.Text.RegularExpressions.Regex.Replace(Test1,“^(”+string.Join(“|”,strText.Split(“,“c))+”)+”,“”)
I have used the above code its not working, correct me if i have done anything wrong here
Expected result is - TESTING IN TEST

@Balan

  1. have you change strText to Test1.

2.and Test1 is your input string or the value fetched from asset?

  1. and also is the expected result is AND|TESTING|IN|TEST

  2. the asset value is like AND,TESTING,IN,TEST ?

Thanks

@Prasanth your code works, i did a minor coding err from my side. Thanks for your effort.

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