How to parse bbcode regex?

I have some trouble to find a regex. I would like to parse all smilies except in bbcode [code].

for example :

[code] :D  :D  :D  :D  [/code] 
 :D :D :D 

My regex must matching the three :D out of bbcode.

I tried (\[code\](.*?)\[\/code\]) to match the bbcode.

But I didn't find how except this block. I find on google how make an exception with (^(\[code\](.*?)\[\/code\])* but not working....

So my first question is : how match all smilley which look likes :D ? and how except a group (bbcode) in regex ?

Thanks for your help

Answers:

Answer

This, I think, should do for you.

(:D)(?=[\s\S]*?\[code\][\s\S]*?\[\/code\]+|(?![\s\S]*?\[\/code\]))

A sample implementation that converts all :D's outside code-tags to links:

document.getElementById('tekt').value = document.getElementById('tekt').value.replace(/(:D)(?=[\s\S]*?\[code\][\s\S]*?\[\/code\]+|(?![\s\S]*?\[\/code\]))/igm,"");

JSFiddle Demo.

Answer

I everyone, I have some problems to construct my regex. Now I need to match all smilley which look like :D except between <code></code> and <img />

I don't understand the exception conception in a group. I found (?!bar).*

the regex :

(:D)(?=[\s\S]*?\<code\>[\s\S]*?\<\/code\>+|(?![\s\S]*?\<\/code\>))|(\<img (?!:D).+ \/>)

Test template

   :D :D :D

[quote="toto"]:D  :D  :D  :D  :D  :D  :D [/quote]

[spoiler="ygfdhy :D  :D  :D  :D "] :D  :D  :D  :D  :D  :D  :D [/spoiler]

[hide] :D  :D  :D  :D  :D  :D  :D [/hide]

<code>  :D  :D  :D  :D  :D  :D  :D </code>

<code>  :D  :D  :D  :D  :D  :D  :D </code>

<img src="#" data-sceditor-emoticon=":D" alt=":D" title=":D" /> 

<img src=#" data-sceditor-emoticon=":D" alt=":D" title=":D" /> 

Regex101

I have 2 problems :

  • I can't no matching smilley in img tag
  • I don't no match just one

Thank for your patience and your expertise

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.