Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'd like to use StringCount to count the number of subwords in a string that have the form **** where * is designed to stand for any character in a specified set:

starSet = {"A","B","C"};
modifiedStringCount[string,"*****"]

For example:

string = "ABAACAWABCAA";

Would generate an output of 2 if Overlaps -> FALSE and a output of 3 is Overlaps -> TRUE. Is there a way to do this?

share|improve this question

1 Answer 1

starSet = {"A", "B", "C"};
StringCount["ABAACAWABCAA", Repeated[starSet, {5}], 
            Overlaps -> False]
2

Edit:

Alternatives is redundant, see the comment of Sjoerd C. de Vries below. Thanks ;)

share|improve this answer
    
I was trying to find a duplicate but I've failed :/ –  Kuba Apr 17 at 11:01
3  
I don't think Alternatives is necessary here. A list of patterns is already interpreted as alternatives. See under Details at the StringExpression page. –  Sjoerd C. de Vries Apr 17 at 11:11
    
@SjoerdC.deVries +1 :) I was not aware of that :) –  Kuba Apr 17 at 11:14
    
Not everyone is aware of Repeated. Just leave it so. –  Sjoerd C. de Vries Apr 17 at 14:49
    
@SjoerdC.deVries Ok, will stay then. –  Kuba Apr 17 at 14:56

Your Answer

 
discard

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.