Regular expression to match content between two strings
PHPz
PHPz 2017-05-19 10:45:11
0
1
961

Regular matching
The following is the string

I am code
##javascript
#var a = 1;
console.log(a);
#javascript
##…
I am Chinese:
The weather is so good today

I am code
##javascript
#var b = 1;
console.log(b);
#javascript
# #…

Now we need to get all the content between ##javascript# and #javascript##. How should we write it? Include all spaces and newlines.

I tried [\s\S]*, but if there are multiple similar pieces of code (as shown above), it will directly match the last #javascript## and not recognize the ones in between. . I'm so helpless, please help. .

Halo, how can the segment editor use non-markdown mode. . . Turn all my code into styles

PHPz
PHPz

学习是最好的投资!

reply all(1)
给我你的怀抱

Regularly, you can use exec to extract multiple values, but there will be dirty data, so it is actually more convenient to use split

var string = '##javascript# var a = 1;console.log(a);#javascript##…我是中文:今天天气真好…我是代码 ##javascript# var b = 1;console.log(b);#javascript##…';
var arr = string.split("#javascript##").map(function(value){
       return value.match(/##javascript#([\s\S]*)/)? value.match(/##javascript#([\s\S]*)/)[1] : value;
    }
);
console.log(arr);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template