Removing everything before a particular String

I have a list of strings - 123xyz, 5617xyz, 789abcxyz.

While printing each item, it should remove anything that is before xyz and print as below -
xyz, xyz, xyz

Trying with regex, but not successful yet. Kindly suggest possible solutions.

is xyz always the last 3 letters? Then just get Right( strvar,3) . I am assuming xyz is a variable ?

xyz is a String, not the last 3 letters always. Consider the input as below -

123xyz, 567abcxyz666, oooxyz

In general, If this is always xyz why you have to regex, just hardcode this


it should remove anything that is before xyz

If your expected result is xyz, xyz666, xyz for the above string list, the following will work.

youStringList = yourStringList.Select(Function(s) System.Text.RegularExpressions.Regex.Match(s,"xyz.*").Value).ToList

And if you want to print it as one string, please try the following method.

String.Join(",", yourStringList)


1 Like