Regular expression that extracts sub-strings that are in some specified format not working for all possibilities

Continuing from my previous question here: Need regular expression that extracts sub-strings that are in some specified format. The solution that was suggested there solved my problem but not completely. I came across another string sample from which the the sub-strings in following format must be extracted:

@[any character here].[any character here].[any character here]……. and so on.

For example, I have a string:

My location is @[XYZ Continent].[XYZ Country].[XYZ State].[XYZ City].[XYZ Street] on the map. You are most welcome there anytime.

Previous solution is working fine on this string. Output:

@[XYZ Continent].[XYZ Country].[XYZ State].[XYZ City].[XYZ Street]

But that solution only checks for + and whitespace outside the sub-string(CLICK HERE TO SEE DEMO). But what I want is that the right and left of the sub-string must be ignored no matter if it is alphnumeric, whitespace or another special character. For example:

Hello@[XYZ Continent1].[XYZ Country1]+@[XYZ Continent2].[XYZ Country2]1@[XYZ Continent3].[XYZ Country3]there.

The output must be:

@[XYZ Continent1].[XYZ Country1]
@[XYZ Continent2].[XYZ Country2]
@[XYZ Continent3].[XYZ Country3]

Solution from previous question:

(?<!w)@(w+b|[.*?](?=[s+]|$))


Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.