Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using regex to get specific string in it's entirity php

I am parsing email raw text bodies, and they have no HTML, so it’s a multi line string essentially.

I thought I created a regex to catch: Quote: #403 I need that back as [Quote, 403] from the entirety of this large string.

So heres an example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$body = "
Test Person
Tester
(123) 123-1234
 <mailto:xxxxxx@xxxxx.com> xxxxxx@xxxxx.com
xxxxxx@xxxxx.com




Your Information:

Name: Last, First
Email: xxxxxx@xxxxx.com <mailto:xxxxxx@xxxxx.co> 
Phone: (123) 123-1234

Quote: #403";

preg_match('/^[a-zA-Z]+: #[0-9]+$/i', $body,$matches);

var_dump($matches); // => array(0) {}

Matches is empty. Based on my understanding this should have worked.

Thoughts?

>Solution :

Try removing the "start" and "end" characters and make it multi-line:

preg_match('/[a-zA-Z]+: #[0-9]+/m', $body,$matches);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading