I am new to PHP regex. I've written below code, but there is something wrong. Could someone please suggest to me what is going wrong?
Input:
1 => 'String',
2 => 'String String',
3 => 'email',
4 => 'date',
5 => 'date',
6 => 'String String',
7 => 'String String',
8 => 'String',
9 => 'date'
Here is the same code from above link:
<?php
$text = "john123 john william johnw@hotmail.com 2015-05-09 13:21:41 2015-08-07 13:21:41 James James William William group1 2015-05-30 18:05:39";
$regex = '~([a-zA-Z]+) ([a-zA-Z]+ [a-zA-Z]+) ([-\w.+]+@[-\w.+]+\.[a-zA-Z]{2,4}) (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ([a-zA-Z]+ [a-zA-Z]+) ([a-zA-Z]+ [a-zA-Z]+) ([a-zA-Z]+) (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})~i';
if ( preg_match( $regex, $text ) ) {
echo $text . " is a valid text. We can accept it.";
} else {
echo $text . " is an invalid text. Please try again.";
}
?>