Skip to main content
1 of 2
gwr
  • 13.6k
  • 2
  • 48
  • 82

Here is how I would do it:

quotePattern = { "\"" , "'", "" };
stringPattern = quotePattern ~~ __ ~~ "by" ~~ __ ~~ quotePattern;

StringMatchQ[ #, stringPattern ] & /@ { "x by y", "\"x by y\"", "'x by y'" }

{ True, True, True }

gwr
  • 13.6k
  • 2
  • 48
  • 82