Find a regular expression matching all the members of this array-php Tutorial

Source: Internet
Author: User
Evaluate a regular array (100-10,-50,200-20,300-30,-30) that matches all the members of this array to obtain a regular expression that matches all the members of this array.


Reply to discussion (solution)

$arr = array('100-10', '-50','200-20', '300-30', '-30');$b = array();foreach ($arr as $value) {if(preg_match("/[\d-]+/", $value,$match)){array_push($b, $match);}}var_dump($b);

$arr = array('100-10', '-50','200-20', '300-30', '-30');$b = array();foreach ($arr as $value) {if(preg_match("/[\d-]+/", $value,$match)){array_push($b, $match);}}var_dump($b);


Thank you, but it's not what I want.
This is what I need.
$ Arr = array ('1970-30', 'lsflsdf ', '50-10', '1970-30','-50 ', '1970-1000 ');
I need to assign different variables to the classes '2014-30' or '-30' and other classes separately.

What is the difference between-and?

$ Arr = array ('1970-10', 'lsflsdf ', '100-20','-50', '1970-20', '1970-30 ', '-30', '2014-1000'); $ a = array (); // store other types $ B = array (); // store foreach ($ arr as $ value) of the type '2014-30' or '-30' {if (preg_match ("/^ [\ d-] + /", $ value, $ match) {array_push ($ B, $ match);} else {array_push ($ a, $ value) ;}} var_dump ($ a, $ B ); // you can get two results for separating different types.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.