Saturday 26 January 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...