-3
my $example=<<EO_STR;

Start

text1 

text2 


text3 Text4

Text5 text6

text7

End

EO_STR

on the following exemple. I want to extract all the text between Start and End(knowing that the text text extract contains spaces and new line and return charriot)

I tried this, but it does not work:

$example=~m/start\s+(.*?)\s+end/i
  • 1
    A belated welcome to the site! Check out the [tour](https://stackoverflow.com/tour) and the [how-to-ask page](https://stackoverflow.com/help/how-to-ask) for more about asking questions that will attract quality answers. You can [edit your question](https://stackoverflow.com/posts/54692932/edit) to include more information. What have you tried so far? – cxw Feb 14 '19 at 14:40
  • Possible duplicate of [Learning Regular Expressions](https://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen Feb 14 '19 at 14:43
  • I already mentioned my code that I tried to do, but it does not work – Red_Developper Feb 14 '19 at 15:20

2 Answers2

1

Line ending, i.e. \n, is a white space, so this can simply be written as

$example =~ /(?i:start)([\w\s]+)(?i:end)/

Is there a particular reason start and end have to be matched case-insensitive? Your example indicates that the regex might be simplified to:

$example =~ /Start([\w\s]+)End/
Stefan Becker
  • 5,695
  • 9
  • 20
  • 30
0

I managed to find the solution thanks to you all

$example=~m/start([a-zA-Z0-9\p{P}\p{S} \s]*)end/i;