Regex to mach string comma separated?

San Nicolás de los Garza, A.B.C., México
San Nicolás de los Garza, ABC., México
San Nicolás de los Garza, A.B., México

How can I match only these: ABC., or A.B.C., or A.B.,

That’s easy A simple “match this or this or this” will work.

*Note the the dot must be backslash escaped in this context so it won’t be a wildcard “any character”

1 Like

Thanks buddy BUT the values are always different and a there are some values that have 1 or 2 or 3 point separators!

I mean the only sting that is constant is that it always start with a letter and ends with .,

I need to check if starts with [a-zA-z] and contains points inside on not and ends with .,

You didn’t say that.

TBH, I suspected as much, but did not question to emphasize a point.
Code will only do what you code it to do.
Give it instructions that you haven’t been clear about and the code, unlike humans, can not guess what you meant.
IMHO this is especially true when writing regex. You need to think about what pattern you want to match, and which patterns you want to not match, as precisely as they need to be.

I could give you a regex based on what I think you mean by the additional information you have provided. But chances are you will then post back something like “oh, but sometimes it has ___”

The fact is, only you know exactly what you will be working with and you need to be as concise as you can be to get any useful guidance.

Instead of ABC examples, please post a representative sample of exactly what you are working with.

This might work


As seen at

1 Like

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