Reputation: 1256
Let's say I have the following string:
{sometext1Asometext2};{sometext3Bsometext4};{sometext5Csometext6}
I want to match this:
{sometext3Bsometext4}
So the text between brackets, but not all matches, only the one containing B.
On the internet I can only find examples of matching everything between 2 characters, not only text containing some specific string inside.
The values of 'sometext' are unknown.
Upvotes: 0
Views: 50
Reputation: 10360
Try this Regex:
{[^}B]*B[^}]*}
OR
{(?=[^}]*B)[^}]*}
Explanation(1st regex):
{
- matches {
[^}B]*
- matches 0+ occurrences of any character that is neither a }
nor B
B
- matches B
[^}]*
- matches 0+ occurrences of any character that is not a }
}
- matches }
Upvotes: 1