Reputation: 3406
I have this regex in C#:
\[.+?\]
This regex extracts the sub-strings enclosed between square brackets. But before doing that I want to remove .
inside these sub-strings. For example, the string
hello,[how are yo.u?]There are [300.2] billion stars in [Milkyw.?ay].
should become
hello,[how are you?]There are [3002] billion stars in [Milkyw?ay].
I am not good at forming regular expression so don't have any idea of how to modify my regex.
Live example here: https://regex101.com/r/pL5uA1/1
Upvotes: 0
Views: 218
Reputation: 174826
To remove all the dots present inside the square brackets.
Regex.Replace(str, @"\.(?=[^\[\]]*\])", "");
To remove dot or ?
.
Regex.Replace(str, @"[.?](?=[^\[\]]*\])", "");
Upvotes: 3