tags:

views:

52

answers:

3

I am using the below pattern to find all the data between two words, placed in multiple lines.

/START(.+?)END/

But this doesn't seems to work as expected. Can someone help me out with a exact pattern.

Thanks.

+1  A: 

Use the s flag : with this flag, dot (.) will match new line characters too.

 /start(.+?)end/s
Amarghosh
No. The multi-line option will only let the start and end of the line be matched by ^ and $ respectively.
Bart Kiers
I thought I edited before anyone saw that - man you are fast. Anyway, `s` is the correct one, right?
Amarghosh
:) Yup, that's the one!
Bart Kiers
+1  A: 

Do you mean you want to match things like

START
  blah blah blah
  more blah
  and even more blah
END

? Since . does not match newlines by default, your regex won't work. You need to supply the single-line (also known as "dot-all") /s flag to make it match the newlines.

/START(.+?)END/s
KennyTM
Note that the s-flag is more widely known as the DOT-ALL flag, AFAIK. Besides that: +1
Bart Kiers
A: 

assuming you can use Python for example.

>>> s="""
... START
...   blah1 blah2
...   more blah  
...   and even more blah
... END blah3 blah4 blah5 START blah 6
... text here here                    
... blah7 END ......                  
... START end END                     
... """                            
>>> for item in s.split("END"):
...     if "START" in item:
...        print item [ item.find("START")+len("START") : ]
...

  blah1 blah2
  more blah
  and even more blah

 blah 6
text here here
blah7
 end

Split your string on "END", go through each splitted items, check for START,and do a substring. Use the split method of your preferred language.

ghostdog74
thanks this works as expected for me.
mike