Reputation: 33
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
Upvotes: 2
Views: 409
Reputation: 33
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" />
I have 2 problems :
Thank for your patience and your expertise
Upvotes: 0
Reputation: 5510
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,"");
Upvotes: 2