I'm going to have a custom tag on my forum, something l开发者_StackOverflowike
[FISH]data|data|data....[/FISH]
In Jquery, how do I loop through all instances of the [FISH] tag and get all the data between it so I can render? It must:
- Match pairs only (IE, print an error or ignore [FISH] which has no corresponding [/FISH]
- Be case insensitive
You can parse such tags with regular expressions. Try:
console.log($('body').text().match(/(\[FISH\][^\[]*\[\/FISH\])/g));
Here is a live snippet
As the commenter mentioned it is not possible using the square brackets but using <> brackets it is as simple as:
$("FISH")
精彩评论