Assume we have text such as the following.
Title: (some text)
My Title [abc]
Content: (some test)
My long content paragraph. With multiple sentences. [abc]
Short Content: (some text)
Short content [abc]
Using Javascript and RegEx, is it possible to extract the text so that it would be as follows.
Title: My Title
Content: My long content paragraph. With multiple sentences.
Short Content: Short content
Basically ignoring new lines and text in the ()
and []
brackets?
I've tried to use Regex but I can't get it to do exactly as I'd like. I'm also getting the issue that when I match Content:
i'm getting a match for both Content:
& Short Content:
however i'd want to only match the occurrence where it is an exact match.
EDIT:
I'm new to RegEx. So far to extract the titles such as Title:, Content: and so on I have
/[A-Za-z]+:|[A-Za-z]+ [A-Za-z]+:|[A-Za-z]+ [A-Za-z]+ [A-Za-z]+:|[A-Za-z]+ [A-Za-z]+ [0-9]+:/g
And then I loop through and use this
[TITLENAME]:.*\n.*
I'm struggling to get past this. My next step would be to loop through the text that is matched above and then remove the bracket stuff. I'm sure there is a better way to do this!