Remove BBCode with Regex in Javascript - Stack Overflow

I am trying to remove BBCode with attributes and content between those tags. I'm using this regula

I am trying to remove BBCode with attributes and content between those tags. I'm using this regular expression that I got here from here. I also tried other regex I found on stackoverflow but they didn't work for me, just the one I copy here is the closest.

([[\/\!]*?[^\[\]]*?])

I added a . before *?]) and it maches the text between the tags but also matches pokemon and I don't want that.

**Regex**: ([[\/\!]*?[^\[\]].*?])

**Text**: I'm a pokemon master and I like
[TAG] this [/TAG] pokemon [TAG] and this [/TAG] text...

I use this web to test regex /

Can anyone help me?

Thanks in advance.

I am trying to remove BBCode with attributes and content between those tags. I'm using this regular expression that I got here from here. I also tried other regex I found on stackoverflow but they didn't work for me, just the one I copy here is the closest.

([[\/\!]*?[^\[\]]*?])

I added a . before *?]) and it maches the text between the tags but also matches pokemon and I don't want that.

**Regex**: ([[\/\!]*?[^\[\]].*?])

**Text**: I'm a pokemon master and I like
[TAG] this [/TAG] pokemon [TAG] and this [/TAG] text...

I use this web to test regex http://regexpal./

Can anyone help me?

Thanks in advance.

Share Improve this question edited May 23, 2017 at 10:34 CommunityBot 11 silver badge asked Aug 19, 2011 at 5:28 Jose AdrianJose Adrian 1,2371 gold badge17 silver badges32 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3
str = str.replace(/\[(\w+)[^\]]*](.*?)\[\/\1]/g, '');

jsFiddle.

This is what you want:

.replace(/\[(\w+)[^\]]*](.*?)\[\/\1]/g, '$2');

JavaScript demo

Basically you catch the value between tags and then replace the whole string with that value.

Using a regex to do this isn't a very clean way of doing it though...

Sorry Alex but you didn;t read it seems.

This should do:

\[(\w+).*?\].*?\[/\1\]

This will look for a closing tag matching the opening tag - and also accept attributes on the opening tag. The JavaScript code should then be:

str = str.replace(/\[(\w+).*?\].*?\[\/\1\]/, "");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745211506a4616867.html

相关推荐

  • Remove BBCode with Regex in Javascript - Stack Overflow

    I am trying to remove BBCode with attributes and content between those tags. I'm using this regula

    9小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信