Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

According to the documentation,

StringCases[{s1, s2, ...}, p]


{StringCases[s1, p], StringCases[s2, p], ...}

but, oddly enough,

StringCases["string", {p1, p2, ...}]

returns the results which match any of the patterns $p_i$, which is essentially equivalent to

Union[{StringCases["string", p1], StringCases["string", p2], ...}]

Is there a way to modify StringCases["string", {p1, p2, ...}] to return just

{StringCases["string", p1], StringCases["string", p2], ...}

in an analogous manner to how StringCases[{s1, s2, ...}, p] does it?

One alternate way to get the same output would be

Through[Table[StringCases[#, p[i]] &, {i, n}]["string"]]

but I was curious if there was another way.

share|improve this question
StringCases["string", #] & /@ {p1, p2} – Kuba Jul 9 '14 at 21:37
@Kuba: Looks good, thanks. – DumpsterDoofus Jul 9 '14 at 23:29
up vote 1 down vote accepted


p = {"abc", "cd"};
string = "abcdabcdcd";

StringCases @@@ Thread[{string, p}]
(* {{"abc", "abc"}, {"cd", "cd", "cd"}} *)

Original post:

StringCases[string, p, Overlaps -> All]
(*  {"abc", "cd", "abc", "cd", "cd"} *)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.