简体   繁体   English

如何使用RegEx从另一个文本中提取多行和空白,包括文本?

[英]How to extract multi line and white space including text from another text using RegEx?

This is my text: 这是我的文字:

[[>
Check this out!

And also this one!

Well, I also have this 
[[MyVariable>5:15]]

I want to extract: 我要提取:

Check this out!

And also this one!

Well, I also have this

and

MyVariable

and

5:15

When it's only [[MyVariable>5:15]] I can extract values using this RegEx: /\\[\\[(.*)\\]\\]/g . 仅当[[MyVariable>5:15]]我可以使用此RegEx提取值:/ /\\[\\[(.*)\\]\\]/g .*) /\\[\\[(.*)\\]\\]/g [[MyVariable>5:15]] / /\\[\\[(.*)\\]\\]/g However, I'm unable to get multi-line version which starts with [[> . 但是,我无法获得以[[>开头]的多行版本。

I tried \\[\\[\\>(\\s\\S)\\]\\] with no luck. 我尝试\\[\\[\\>(\\s\\S)\\]\\]没有运气。

How do I get what I want? 我如何得到想要的东西?

(I'm using JavaScript) (我正在使用JavaScript)

I see [[..>..]] as a structure which you need to deal with it. 我认为[[..>..]]是您需要处理的结构。 If you want to capture everything before and after > : 如果要捕获>之前和之后的所有内容:

\[\[([^>]*)>([^[\]]*)

Live demo 现场演示

I think you're looking for something like this. 我认为您正在寻找类似的东西。

/([^\[\[>]*)[A-Za-z0-9]([^>[\]]*)/g

If you haven't heard of it, regexr is a pretty cool place to experiment with regex. 如果您还没有听说过, regexr是尝试regex的好地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM