Adam Mo.
Adam Mo.

Reputation: 772

Regular expression failed replace

I want to use Regular expression to replace this text :

[Button size="Big" color="#000"] test [/Button]

to Button, I used this site http://www.freeformatter.com/regex-tester.html but not working the replace.
the Regular expression \[Button([^\]]*)\[/Button],it give me the result String is same as before replace! what the mistake?

Upvotes: 2

Views: 105

Answers (3)

Rohit Jain
Rohit Jain

Reputation: 213253

The ([^\]]*) part of your regex will stop matching before the closing ] of first tag. So, you don't have the pattern to match string - "] test " thereafter.

Modify your regex to:

\[Button([^\]]*][^\[]*)\[/Button]

Upvotes: 2

cristobalito
cristobalito

Reputation: 4282

The regex of

\[Button.*\]

and the replacement string of Button should be enough.

Upvotes: 0

MightyPork
MightyPork

Reputation: 18861

Try with this, it matches properly and also matches the insides.

\[Button([^\]]*)\](.*?)\[/Button\]

Upvotes: 1

Related Questions