0

I am very new to CakePHP and not very familiar with regular expressions.

I need to use regex in CakePHP to check whether a string has a double quotes character, followed immediately by a comma, then followed by another double quotes character: ","

Here is my attempt: String::tokenize($problem_string, '/",/"');

I tried ($problem_string, ","), but that parsed the string at every place there was a comma. I also tried ($problem_string, "/",/""), with no luck.

This entry suggests using a backslash in front of the double quotes in Java, but maybe that rule doesn't apply for PHP or CakePHP? How to represent the double quotes character (") in regex?

I feel like this should be an easy problem to figure out, but I've been stumped for quite a while now.

Community
  • 1
  • 1
sthompso
  • 131
  • 1
  • 4

1 Answers1

1

The escape character you're looking for is the backslash not the forward slash, but you don't have to escape double quotes if you use single quote delimiters, so just this: ($problem_string, '/","/')

Update

After reading String::tokenize docs, and not seeing any mention of regex, I think you just want ($problem_string, '","')

smathy
  • 26,283
  • 5
  • 48
  • 68
  • 1
    Thanks for responding. I tried ($problem_string, '/","/') but had no luck. I also tried ($problem_string, '\","\'), ($problem_string, '\",\"'), and ($problem_string, '","'). I did notice that substr_count($problem_string, '","') works fine, which seems strange. – sthompso Nov 11 '14 at 01:00
  • I'm looking up `String::tokenize` and nothing in there suggests that the second argument is a regex, what makes you think this has anything to do with regex? – smathy Nov 11 '14 at 01:03
  • Did you notice that I updated my answer with a non-regex solution? Does that work? (also, don't forget to upvote the people here who took the time to steer you in the right direction - it's the StackOverflow way) – smathy Nov 11 '14 at 17:50