Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. preg_replace('/b^(true|false|TRUE|FALSE)b/', '', 'false'); // Returns an empty string, but i expect 'false'
  2.  
  3. preg_replace('/b^(true|false|TRUE|FALSE)b/', '', 'test') // Returns 'test', but i expect an empty string
  4.  
  5. preg_replace('/b^(true|false|TRUE|FALSE)b/', '', 'This regex allow only boolean, such as true, false, TRUE and FALSE');
  6.  
  7. // This regex allow only boolean, such true, false, TRUE and FALSE
  8.  
  9. $arr = array('true', 'false', 'TRUE', 'FALSE');
  10.  
  11. $result = (in_array($str, $arr, true)) ? $str : '';
  12.  
  13. $re = '/b(?!(?:true|false|TRUE|FALSE))w+b/';
  14. $str = 'I need true to allow only false specific FALSE words in a TRUE string';
  15.  
  16. $repl = preg_replace($re, "", $str);
  17. //=> true false FALSE TRUE
  18.  
  19. if (preg_match('/^(true|false|TRUE|FALSE)$/', $string, $match)) {
  20. echo "Found : ",$m[1],"n";
  21. } else {
  22. echo "Not foundn";
  23. }
  24.  
  25. $regex = '/(?=.)(true|false|TRUE|FALSE|\s{0,})(?!.)/';
  26. $testString = ''; // Fill this in
  27. preg_match($regex, $testString, $matches);
  28. // the $matches variable contains the list of matches
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement