PHP Regex error -


i new php regex. i've written below code, there wrong. please suggest me going wrong?

code link

input:

    1 => 'string',     2 => 'string string',     3 => 'email',     4 => 'date',     5 => 'date',     6 => 'string string',     7 => 'string string',     8 => 'string',     9 => 'date' 

here same code 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 . " valid text. can accept it.";     } else {           echo $text . " invalid text. please try again.";     }   ?> 

in test string john123 , group1 has digits trying match [a-za-z]+ make them [a-za-z\d]+ , other groups digits possible.. use following:

([a-za-z\d]+) ([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]+) (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) 

edit: since using i (case insentitive) modifier.. can have [a-z]+ alphabet , [a-z\d]+ alphanumeric characters.

see demo


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -