Regex: To pull out a sub-string between two tags in a string

后端 未结 9 1982
情书的邮戳
情书的邮戳 2020-12-08 00:35

I have a file in the following format:

Data Data
Data
[Start]
Data I want
[End]
Data

I\'d like to grab the Data I want from between the

9条回答
  •  没有蜡笔的小新
    2020-12-08 00:56

    Well, if you guarantee that each start tag is followed by an end tag then the following would work.

    \[start\](.*?)\[end\]
    

    However, If you have complex text such as the follwoing:

    [start] sometext [start] sometext2 [end] sometext [end]
    

    then you would run into problems with regex.

    Now the following example will pull out all the hot links in a page:

    '//i'
    

    In the above case we can guarantee that there would not be any nested cases of:

    ''
    

    So, this is a complex question and can't just be solved with a simple answer.

提交回复
热议问题