-1

I want to have such a method leastMatch(String input, String regExp, int n)
input is the input text, regExp is the regular expression and n is the minimal amount of characters the result has.
The return value is a head of the input text which matches the regular expression and contain at least n characters.

e.g.
leastMatch("abababab", "(ab)+", 3) //returns "abab"
leastMatch("abababab", "(ab)+", 0) //returns ""
leastMatch("abababab", "(ab)+", 4) //returns "abab"

elmar
  • 41
  • 1
  • 6

1 Answers1

0

use this syntaxe:

(ab){3,}    --> 3 or more
(ab){0,2}   --> less than 3
(ab){2,5}   --> between 2 and 5
(ab){3}     --> 3

you can easily determine the number of ab you allow with n and ab length (2 in this example)

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
  • it's not what I want. The regular expression is dynamic. Consider what if the regular expression is a*. – elmar May 29 '13 at 12:11