In this kata you should find BB-tags (bulletin board tags) in given string.
BB-tags look like:
[B]Some content[/B],
where [B] - opening tag and [/B] - closing tag.
Name of tags also can be lowercase:
[url]Some content[/url]
And BB-tags can be nested into each other, for example:
[url][b][size=5][color=blue]Some content[/color][/size][/b][/url]
If there is nested BB-tags, you should return only the outer tag with all it's content (with another tags into it).
function test(str) {
return (str.match(/\[([a-zA-Z]+)](.*)\[\/\1]/g)).join('');
}
describe("Finding 'BB'-tags in text", function(){
it("Testing for singular pair of tags", function(){
Test.assertEquals(test("Так записывается ссылка: [url]http://ya.ru[/url]"),"[url]http://ya.ru[/url]");
});
it("Testing for two pair of tags", function(){
Test.assertEquals(test("Ссылка, текст которой выделен жирным: [url][b]http://ya.ru[/b][/url]"), "[url][b]http://ya.ru[/b][/url]");
});
it("Testing for empty content of tags", function(){
Test.assertEquals(test("Теги без содержимого: [url][/url]"), "[url][/url]");
});
it("Testing for empty content of several tags", function(){
Test.assertEquals(test("Выделенная жирным цитата со ссылкой на источник(которого нет): [url][b][quote][/quote][/b][/url]"), "[url][b][quote][/quote][/b][/url]");
});
it("Testing for a lot of nested tags", function(){
Test.assertEquals(test("It should work for a lot of different nested tags: [url][b][size=5][color=blue]Some content[/color][/size][/b][/url]"), "[url][b][size=5][color=blue]Some content[/color][/size][/b][/url]");
});
});