Mihael Keehl
Mihael Keehl

Reputation: 355

Parse custom tags using Javascript

Let's say that I want to write a website that could dynamically create tests on a diversity of subjects. The summery of these subjects are saved in a database, and the important parts of the text are between two tags, which I eventually want to check. I want to accomplish it by putting tags between certain words or sentences of a paragraph like this:

Summary in database:

Aristotle lived from [BEGIN] 384 to 322 [/END] was a Greek philosopher and scientist born in the Macedonian city of Stagira, Chalkidice, on the northern periphery of [BEGIN]Classical Greece[/END].

What I want is to read and retrieve the text between the two tags using Javascript which could be in any format, in this example I used [begin] and [/end] but any format will do, like:

Is there any way to accomplish this by using Javascript or potentially JQuery?

Upvotes: 0

Views: 375

Answers (1)

Derek 朕會功夫
Derek 朕會功夫

Reputation: 94379

Why not just use a simple regex if it's for personal usage?

/\[BEGIN\](.*?)\[\/END\]/g

http://jsfiddle.net/DerekL/fbdy9c20/

Upvotes: 2

Related Questions