<?php $test = '-1 -134123 -1 -1'; preg_match_all("/\b-1\b/" , $test , $match); print_r($match); ?> PHP: i am trying to match only -1 and not -1224 (that is why i used boundaries) but code does not work (it works for positive numbers)
preg_match_all("|(-[0-1]{1})|" , $test , $match); PHP: Should match negative any 1 number. I don't think so, but you might need to escape the negative sign. Peace,
Try -1[^0-9] That means -1 and it cant be followed by a number. I don't know about boundary, but if you using doublequote, you need to escape it \\b
This work $test = '-1 -134123 -1 -1'; preg_match_all("~-1( |$)~" , $test , $match); print_r($match); Code (markup):
using \\b doesnt work and -1[^0-9] doesnt solve my purpose .. Thanks for helping though Edit this works great beacon Thanks! what if i want it to match -1 or 1 ?
Use <?php $test = '-1 -134123 -1 -1'; preg_match_all('/\-1\b/' , $test , $match); print_r($match); PHP: it returns Array ( [0] => Array ( [0] => -1 [1] => -1 [2] => -1 ) ) Code (markup):