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
StringCount["one letters three letters letters one letters letters three letters",
"one" ~~ __ ~~ "three"]

gives

1

because there is the one occurence of "one [letters three letters letters one letters letters] three [letters]"

It took me some time to understand that Mathematica "thinks" in this way because I expected the value

2

due to "one letters three letters letters one letters letters three letters"

Now I am facing the problem of finding the code that solves this problem in my desired way.

share|improve this question
6  
Use Shortest[__] – R. M. May 14 '14 at 21:40
    
See also: mathematica.stackexchange.com/q/6998/4330 – Jacob Akkerboom May 15 '14 at 15:35

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.