Syzak
Syzak

Reputation: 153

Regex match without specific word

I'm looking for regex that matches only the first occurrence of the expression.

An expression: [B]text[/B], And I have regex for that

\[[B]]([a-z0-9 ./,<>()!@#$%^&*+=;:'"\[\]\\|\t\n-]*)\[\/[B]]

But that expression may occurs few times, for example:
[B]test1[/B]
[B]test2[/B]

When that happens it looks like that:
test1[/B]
[B]test2

Instead of just test1 and test2 So I'm looking for some way to stop searching when it finds [/B], I know I allowed regex searching for "][/" but I want it not allowed when it's an expression "[\B]"

Upvotes: 0

Views: 53

Answers (1)

Kamil Kiełczewski
Kamil Kiełczewski

Reputation: 92617

Try this

\[B\](.*?)\[\/B\]

Here is snippet. Explanation here.

Upvotes: 1

Related Questions