FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Regex





eudbase
How to write a regex to extract the sentences below:
abc | letter | using the letter [writer] | 123 | number | calculate the number [maths]

I need to extract the data like
abc, letter, using the letter [writer]
123, number, calculate the number [maths]

I can`t separate the two records of data by using following code:

Code:

$devline='abc | letter | using the letter [writer] | 123 | number | calculate the number [maths]';
if(preg_match("/([a-z]*|.*|.*[.*]) [a-z]*|/", $devline, $matches)){
      print_r($matches);
}


Please correct my coding or show me some better regex. Thanks.
rvec
better not use regex for that. This is the php forum after all so I'll use php to seperate them all.

Code:
$your_string = "abc | letter | using the letter [writer] | 123 | number | calculate the number [maths] ";
$array = explode(" | ", $your_string);
var_dump($array);

Smile
Related topics
SOFTWARE OR MANUAL
PHP DB Error: syntax error
Avec quel éditeur de texte codez vous en php?
Form validation
Needing a Bit Og Help {PHP}!
PHP Regex
login systeem
SSI within php coded files
[JS] Regular expressions global match get first group
htmlspecialchars
Perl regex help
Just a little Regex problem
$200 for JS search and replace regex
Can someone tell what exactly this regex do
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.