How to extract out the variable of special content format?
I have below data:
# == 2.This is a ==
111111
222222
# == 2.This is a ==
# == 3.This is b ==
333333
# == 3.This is b ==
4
5
# == 2.This is a ==
66
77
8
# == 2.This is a ==
# == 4.This is c ==
9
# == 5.This is d ==
11
12
13
# == 5.This is d ==
10
# == 4.This is c ==
you see the special format # == {variable} ==
I want to extract out the variables.
but I don’t know how to do with this, I have searched SO,
but neither is suitable for this situation.
and before asking this question I have tried:
var pattern = /# == ([a-zA-Z0-9.\s]+) ==/g
var matchArr=content.match(pattern)
but I want to extract out the ([a-zA-Z0-9.\s]+) not /# == ([a-zA-Z0-9.\s]+) ==.
>Solution :
I’m not sure how to implement the solution in Javascript, but you can try something like this regex:
# == ([0-9.\sa-zA-Z]+)
See the solution in action here:
https://regex101.com/r/OCLO1k/1