Say I'd like to pick substrings from some string such that these substrings have the pattern @@@q@@@, where @ is used here as a stand-in for a 'wildcard' character (i.e. any character) and q is just an example of a specific character that can be specified as desired.
The kind of lame solution might be as follows:
substringList = StringTake[testString, # + {-3, 3} & /@ StringPosition[testString, "q"]];
This, of course, runs into trouble when q appears near one of the two ends of testString.
What's the correct way to do this?
StringCases? The tutorials at the bottom of theStringCasesdocumentation (specifically, the ones on String Patterns) will also come in useful. – Aky Apr 04 '14 at 17:46x~~? – CA30 Apr 04 '14 at 17:47~joins patterns only. p.s. is each wildcard different? – Kuba Apr 04 '14 at 17:50StringCases["acaqaddqccxjq", RegularExpression["...q..."], Overlaps -> True], which returns{"acaqadd", "addqccx"}– Aky Apr 04 '14 at 17:54Mathematica) – Aky Apr 04 '14 at 18:00StringCasesdocumentation. If you leave outOverlaps -> True(which is the same as sayingOverlaps -> False) the second substring is not outputted, because its first three characters ("add") overlap with the last three characters of the first matched substring. – Aky Apr 04 '14 at 18:13