2

Here is the sample string with my regex and code:

$str = "Supp Fees:
----------
Oral Glucose
Glucagon
OXYGEN";

$ptn = "/----------(?:\r\n(.+))+/m";
preg_match_all($ptn,$str,$matches);

echo"<pre>";
print_r($matches);
echo"</pre>";

I'm trying to match every line after '----------' the pattern above only returns the first line (Oral Glucose). I can repeat the '\r\n(.+)' part and return another line but there is no telling how many lines there will be.

Thanks!

2 Answers 2

2

You could do this without regex:

$data = substr($str, strpos($str, '----------') + 10);
$matches = explode("\r\n", $data);
Sign up to request clarification or add additional context in comments.

1 Comment

You mean solving a string problem without REGEX!>!>!>!?! lol, it's funny how I've been using REGEX so much lately I didn't even consider using php functions. thanks.
1
<?php

$str = "Supp Fees:
----------
Oral Glucose
Glucagon
OXYGEN";


$str = explode('----------', $str);
preg_match_all("/[^\r\n].*/", $str[1], $matches);

echo"<pre>";
print_r($matches);
echo"</pre>";

?>

?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.