1

I would like to parse the text

==== Example 1 ====
Some text that doesn't contain 4 equals signs
==== Example 2 ====
More text that doesn't contain 4 equals signs
==== Example 3 ====
Even more text that doesn't contain 4 equals signs

My goal is to get an array with elements "Example 1", "Example 2", and "Example 3" using RegEx in Perl. I'm a beginner in Perl and RegEx, so initially I used the greedy method which returned text I din't want. When I later used a non-greedy method, I was only able to get "Example 1." My latest attempt:

my @matches = ($text =~ /====(*?[ -~\s])====/g);

Edit: I realize how to do this; instead I want to return multiple matches instead of one.

Community
  • 1
  • 1
KingBob
  • 37
  • 5
  • Did you try the global modifier at the end of your RegEx? [`/regex/g`](http://stackoverflow.com/questions/948795/how-can-i-do-a-global-regular-expression-match-in-perl). – Sam Jan 27 '14 at 23:06
  • 1
    "*... initially I used ... When I later used ...*" Can you include a snippet of code from your attempts? Showing precisely [what you've tried](http://whathaveyoutried.com) can help in providing a useful answer. – Jonathan Lonowski Jan 27 '14 at 23:07
  • @JonathanLonowski I've just added what I've tried. – KingBob Jan 27 '14 at 23:13
  • Why not `/====\s?(.*?)\s?====/g`? Not perfect, but if your cases are pretty simple... – Robin Jan 27 '14 at 23:15

1 Answers1

4

Why not /====\s?(.*?)\s?====/g?

Not perfect, but if your cases are pretty simple...

Robin
  • 9,415
  • 3
  • 34
  • 45