Searching a specific word and getting all the strings in a line with a condition

Hi All,
I wanted to get the string line that contains “College” or “University” using regex but will remove any symbols or numbers.

Input:
School: Angeles University Foundation
2021 University of Baguio

Output:
Angeles University Foundation
University of Baguio

Thanks in advance!

Hi,

Hope the following helps you.

System.Text.RegularExpressions.Regex.Matches(yourString,"[A-Za-z ]*(University|College)[A-Za-z ]*")

Sequence3.xaml (6.8 KB)

Regards,

2 Likes

Thanks Yoichi! It worked perfectly fine.

1 Like

Currently I am using Match activity and put the regex code and then I am printing out the first result as school(0).ToString but I wanted to put an If condition that once the string contains “Bachelor” it will find the next string, technically school(1).ToString

Hi,

Do you mean as the following?

Sequence3.xaml (7.9 KB)

Regards,

1 Like

Thanks for this. I’ve made some revisions on it but this helps me a lot.

1 Like

Hi Yoichi,

I have a following question. Since we already created the expression [A-Za-z ](University|College)[A-Za-z ] and will get all the words before and after the word “University” or “College”, I also wanted to know how to remove a specific word on it. For example, in the line of string it says “Events University of Baguio” how can I remove the word “Events” on it? Can I include it to the regex expression? If yes, how?

Thanks in advance.

Hi,

I think String.Replace or Regex.Replace is better than single regex match because of maintainability. It can handle multiple exclude keywords easily. For example, as the following.

Regards,

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