0

My logic is to find whether the file contains specific version text. For example the file may contain

act 1.9
ACT 1.4
MA 1.2
ma 1.9
...

I want to return true if my file contain any of the above text. Meaning the text to be searched in case Insensitive and the version may be anything from 0.0 to 9.0

So i wrote the regular expression as below:

    final Map<String, Float> outdatedPatterns = new HashMap<String, Float>();
    outdatedPatterns.put("act\\s*_*([0-9.]+)", Float.parseFloat("5.4"));
    outdatedPatterns.put("ma\\s*_*([0-9.]+)", Float.parseFloat("5.3"));

    for (Map.Entry entry : outdatedPatterns.entrySet()) {
        String regex = (String) entry.getKey();
        Float minSupportedVersion = (Float) entry.getValue();
        Pattern outdatedPattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher outdatedPatternMatcher = outdatedPattern.matcher(content);
        while (outdatedPatternMatcher.find()) {
            /* stuff  */

Problem with this logic is, the logic considers following texts also true

schema 1.4
react 3.0

But all i wanted is to search the whole string act and ma only.
Kindly suggest how to change my regular expression to solve the issue

Treycos
  • 7,373
  • 3
  • 24
  • 47
Akshe
  • 21
  • 4

0 Answers0