Saturday, January 26, 2019

regex - Match text after colon and before new line - Javascript

I have a text in the following format:


Concept number 1: my content here1
Concept number 2: my content here2
Concept number 3: my content here3

I want a regext to get the text after Concept number 1:. So I want to get the following: my content here1.


I was using Concept number 1(.*?)
, but I'm getting the whole string as a result instead of the text after the colon.


Demo online.


var text = $('.text').html();
var regex = new RegExp('Concept number 1:(.*?)
', "g");
var matches = text.match(regex);
//matches contains `Concept number 1: my content here1
`

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...