String match

I am building a use case where I have to read a string from an application and use if condition to check whether that string contains Keyword GB at last.
I have used if condition as io_strName.ToString.Contains(“GB”) but I think it will pick those cases as well where GB keyword can be anywhere in the string. But I want to pick those cases only where GB keyword comes as Last.

For example:
The cases are:
NEW ENGLAND GB
Rogers GB
Integrated Solutions GB, etc

@Principal_htga In the third case there is etc at the end is it part of that case or is it the normal etc :sweat_smile:

Normal

@Principal_htga Are there any cases where the Word “GB” is at the Beginning or in Between and Do you want to match that as well or not?

@Principal_htga This Regex expression might help considering the values will be only Alphabets, spaces and numbers.

There might be a chance that GB keyword can come in beginning or middle. But I only want to match the case where it is at the End.
For example:
HasGBghnk GB
ucnakcGB GB
GBucnakc GB

Above cases, GB is thereat beginning and in middle along with End as well. Bot should ignore whats there at begin or in middle, it should only check at end.

@Principal_htga What about the data, are they only alphabets or numbers or can there be Special characters as well?

Only Alphabets

@Principal_htga, i have a different approach

How about you use substring to solve this, so in your if activity, use something like:

YourString.SubString(YourString.Length - 2).Equals("GB")

The substring will return the last two character of the word

1 Like

Hi @Principal_htga

Using this Regex [a-zA-Z0-9 ]+GB$ for your problem.

You can check this regex at https://regex101.com/.

Regards
Achal Sharma

Hi,

I want to learn Regex, can u please guide me as I’m a beginner. Its totally confusing for me.

Thanks in advance.

Hi @saritha

You can learning the regex building from Regex Learning for Beginners and you can test your regex at https://regex101.com/.

Regards
Achal Sharma

Thank you.
Will look at it.

Thanks that worked

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