-1

I don't know how to create a regular expression. I wanted to get subtrings from a string. In my case the string is [_formatdate_form_date "D, d M y"]. I wanted the field name form_date and the string between the double quotes i.e. D, d M y. I searched for the PHP functions like preg_match but all requires a pattern. So how to create a pattern for this

Sanjay Goswami
  • 822
  • 1
  • 16
  • 36
  • 2
    Sorry, but this is not a place to request private tutorials. I suggest you read one of the many "getting started" tutorials dealing with regular expressions. Also online regex utilities are a great help to play around. And there are really good books about that topic too... – arkascha Nov 04 '16 at 09:50

1 Answers1

2

You can do something like that :

$str = '[_formatdate_form_date "D, d M y"]';
$regex = "/_formatdate_(.*)\s\"(.*)\"/";

preg_match_all($regex, $str, $matches);
var_dump($matches);

And the result $matches :

enter image description here

So to acces you have to do : $matches[1][0] or $matches[2][0]

But to understand what does it make, I suggest you to learn a minimum about regular expression : Learn Regular Expression

Berserk
  • 821
  • 12
  • 23