It sounds like you'll have to modify the script to first strip out any accepted tags and then count what remains. Assuming you want to support a subset of the BBCode tags, you could do something like this:
var stripBBCode = function(value){
var tags = new Array('b', 'i', 'u', 'url', 'quote'); var result = value;
for( var index in tags){ var oRegExp = new RegExp('\\[' + tags[index] + '](.*?)\\[/' + tags[index] + ']'); result = result.replace(oRegExp, \"$1\"); oRegExp = null; }
return result; }
I don't guarantee this will work perfectly in all circumstances, but I think you can see where I'm going and expand it to suite your needs.
I've found a little glitch, the expression matches
[tag]four[/tag]
just fine (as 4 chars), but
[url=someurlhere]test[url]
fails.
I've tried some things but none are working for me. Is there a simple fix? As most others I'm not too fond of the syntax =) This is the current expression:
new RegExp('\\[' + tags[index] + '](.*?)\\[/' + tags[index] + ']');
This doesn't work for about 10 different reasons. The most important part is that you've split the expression up into two different sections that repeat basically the same expression which renders the replace part of the code unusable; you've also introduced new capture groups that are unused so they provide a big performance penalty.
I've modified the original expression to make an "=something" optional:
new RegExp('\\[' + tags[index] + '(?:=.+?)?](.*?)\\[/' + tags[index] + ']');
Notice that I made the "=something" group non-capturing. This way, we still only have 1 capturing group to the replace code works as is. I've also added the requirement that something must come after the equals sign, otherwise this would match: "something"; if you don't want this requirement, change the + to a *.
Let me know if there are any other glitches and I'll be glad to give it another look.
I need a script to manage maxlength in a textarea. I'm currently using one from anon-design, which is working just fine.
There's one big problem tho. It parses
Thanks,
Oskar
I don't guarantee this will work perfectly in all circumstances, but I think you can see where I'm going and expand it to suite your needs.
I've tried some things but none are working for me. Is there a simple fix? As most others I'm not too fond of the syntax =) This is the current expression:
new RegExp('\\[' + tags[index] + '](.*?)\\[/' + tags[index] + ']');new RegExp('\\[' + tags[index] + '](.*?)\\[/' + tags[index] + ']||\[' + tags[index] + '\=(.*?)\](.*?)\\[/' + tags[index] + ']');This doesn't work for about 10 different reasons. The most important part is that you've split the expression up into two different sections that repeat basically the same expression which renders the replace part of the code unusable; you've also introduced new capture groups that are unused so they provide a big performance penalty.
I've modified the original expression to make an "=something" optional:
new RegExp('\\[' + tags[index] + '(?:=.+?)?](.*?)\\[/' + tags[index] + ']');Notice that I made the "=something" group non-capturing. This way, we still only have 1 capturing group to the replace code works as is. I've also added the requirement that something must come after the equals sign, otherwise this would match: "something"; if you don't want this requirement, change the + to a *.
Let me know if there are any other glitches and I'll be glad to give it another look.