-2

I have following string

Casas (3)

I want to get the number three out of it .

in Jquery I am using this regex

regExp = /\(([^)]+)\)/;

But i dont know how to do that in PHP

Thanks in advance

Vikram Anand Bhushan
  • 4,836
  • 15
  • 68
  • 130

3 Answers3

2

You can try something like this :

<?php 
$text = 'Casas (3)';
preg_match('#\((.*?)\)#', $text, $match);
print $match[1];

?>

Hope it helps..

Jenis Patel
  • 1,617
  • 1
  • 13
  • 20
1

Try this

$str = "Casas (3)";
preg_match_all('!\d+!', $str, $matches);
print_r($matches);
Bhavya Shaktawat
  • 2,504
  • 1
  • 13
  • 11
  • Just out of curiosity: What is the difference to [this](http://stackoverflow.com/a/6278312/3933332) besides the string? If answer = none -> this would be a dupe – Rizier123 Feb 24 '15 at 06:07
  • yeah..i dint check it..as there are lot of preg match question answers available... – Bhavya Shaktawat Feb 24 '15 at 06:54
0

Use preg_match with your regular expression

$f = 'Casas (3)';
preg_match('/\(([^)]+)\)/', $f, $fr)
echo $fr[1];
Vinie
  • 2,983
  • 1
  • 18
  • 29