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

后端 未结 9 1947
情书的邮戳
情书的邮戳 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:47

    With Perl you can surround the data you want with ()'s and pull it out later, perhaps other languages have a similar feature.

    if ($s_output =~ /(data data data data START(data data data)END (data data)/) 
    {
        $dataAllOfIt = $1;      # 1 full string
        $dataInMiddle = $2;     # 2 Middle Data
        $dataAtEnd = $3;        # 3 End Data
    }
    

提交回复
热议问题