Skip to main content
added 26 characters in body
Source Link
Maksim Dmitriev
  • 1.4k
  • 3
  • 16
  • 29

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

package com.sandbox;

import java.util.regex.Matcher; import java.util.regex.Pattern;

public class Main {

package com.sandbox;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
/**
 * @param args
 */
public static void main(String[] args) {
    checkVersion("10.22.5-r");
}

private static void checkVersion(String current) {
    String regex = "([1-9]\\d*)\\.(\\d+)\\.(\\d+)-[b|r](?:[1-9]\\d*)*";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcherCurrent = pattern.matcher(current);
    System.out.println("Matches: " + matcherCurrent.matches());
    System.out.println("The first digit: " + matcherCurrent.group(1));
    System.out.println("The second digit: " + matcherCurrent.group(2));
    System.out.println("The third digit: " + matcherCurrent.group(3));
    
    // Compare and decide whether an update is necessary
}

}

Thank you for the answers you give me. I'll vote up as soon as I have enough reputation.

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

package com.sandbox;

import java.util.regex.Matcher; import java.util.regex.Pattern;

public class Main {

/**
 * @param args
 */
public static void main(String[] args) {
    checkVersion("10.22.5-r");
}

private static void checkVersion(String current) {
    String regex = "([1-9]\\d*)\\.(\\d+)\\.(\\d+)-[b|r](?:[1-9]\\d*)*";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcherCurrent = pattern.matcher(current);
    System.out.println("Matches: " + matcherCurrent.matches());
    System.out.println("The first digit: " + matcherCurrent.group(1));
    System.out.println("The second digit: " + matcherCurrent.group(2));
    System.out.println("The third digit: " + matcherCurrent.group(3));
    
    // Compare and decide whether an update is necessary
}

}

Thank you for the answers you give me. I'll vote up as soon as I have enough reputation.

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

package com.sandbox;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
/**
 * @param args
 */
public static void main(String[] args) {
    checkVersion("10.22.5-r");
}

private static void checkVersion(String current) {
    String regex = "([1-9]\\d*)\\.(\\d+)\\.(\\d+)-[b|r](?:[1-9]\\d*)*";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcherCurrent = pattern.matcher(current);
    System.out.println("Matches: " + matcherCurrent.matches());
    System.out.println("The first digit: " + matcherCurrent.group(1));
    System.out.println("The second digit: " + matcherCurrent.group(2));
    System.out.println("The third digit: " + matcherCurrent.group(3));
    
    // Compare and decide whether an update is necessary
}

}

Thank you for the answers you give me. I'll vote up as soon as I have enough reputation.

added 162 characters in body
Source Link
Maksim Dmitriev
  • 1.4k
  • 3
  • 16
  • 29

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

package com.sandbox;

import java.util.regex.Matcher; import java.util.regex.Pattern;

public class Main {

public class Main {

/**
 * @param args
 */
public static void main(String[] args) {
    checkVersion("10.22.5-r");
}

private static void checkVersion(String current) {
    String regex = "([1-9]\\d*)\\.(\\d+)\\.(\\d+)-[b|r](?:[1-9]\\d*)*";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcherCurrent = pattern.matcher(current);
    System.out.println("Matches: " + matcherCurrent.matches());
    System.out.println("The first digit: " + matcherCurrent.group(1));
    System.out.println("The second digit: " + matcherCurrent.group(2));
    System.out.println("The third digit: " + matcherCurrent.group(3));
    
    // Compare and decide whether an update is necessary
}

}

Thank you for the answers you give me. I'll vote up as soon as I have enough reputation.

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

public class Main {

/**
 * @param args
 */
public static void main(String[] args) {
    checkVersion("10.22.5-r");
}

private static void checkVersion(String current) {
    String regex = "([1-9]\\d*)\\.(\\d+)\\.(\\d+)-[b|r](?:[1-9]\\d*)*";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcherCurrent = pattern.matcher(current);
    System.out.println("Matches: " + matcherCurrent.matches());
    System.out.println("The first digit: " + matcherCurrent.group(1));
    System.out.println("The second digit: " + matcherCurrent.group(2));
    System.out.println("The third digit: " + matcherCurrent.group(3));
}

}

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

package com.sandbox;

import java.util.regex.Matcher; import java.util.regex.Pattern;

public class Main {

/**
 * @param args
 */
public static void main(String[] args) {
    checkVersion("10.22.5-r");
}

private static void checkVersion(String current) {
    String regex = "([1-9]\\d*)\\.(\\d+)\\.(\\d+)-[b|r](?:[1-9]\\d*)*";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcherCurrent = pattern.matcher(current);
    System.out.println("Matches: " + matcherCurrent.matches());
    System.out.println("The first digit: " + matcherCurrent.group(1));
    System.out.println("The second digit: " + matcherCurrent.group(2));
    System.out.println("The third digit: " + matcherCurrent.group(3));
    
    // Compare and decide whether an update is necessary
}

}

Thank you for the answers you give me. I'll vote up as soon as I have enough reputation.

Edit the pattern
Source Link
Maksim Dmitriev
  • 1.4k
  • 3
  • 16
  • 29

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

package com.sandbox;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        checkVersion("10.022.25-r1000"r");
    }

    private static void checkVersion(String current) {
        String regex = "[1"([1-9]\\d*\\.\\d+\\9]\\d*)\\.\\d+(-\\d+)\\.(b|r\\d+)*-[b|r](?:[1-9]\\d*)*){0,1}";*";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcherCurrent = pattern.matcher(current);
        System.out.println("Matches: " + matcherCurrent.matches());
    System.out.println("The first digit: " + matcherCurrent.group(1));
    System.out.println("Groups"The second digit: " + matcherCurrent.groupCountgroup(2));
    }
System.out.println("The third digit: " + matcherCurrent.group(3));
}

}

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

package com.sandbox;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        checkVersion("10.0.2-r1000");
    }

    private static void checkVersion(String current) {
        String regex = "[1-9]\\d*\\.\\d+\\.\\d+(-(b|r)*([1-9]\\d*)*){0,1}";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcherCurrent = pattern.matcher(current);
        System.out.println("Matches: " + matcherCurrent.matches());
        System.out.println("Groups: " + matcherCurrent.groupCount());
    }

}

Only these formats are accepted.

  1. 1.1.1
  2. 1.1.1-r
  3. 1.1.1-b
  4. 1.1.1-r1
  5. 1.1.1-b1

I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do anything with groups. And there might be some bugs as well.

public class Main {

/**
 * @param args
 */
public static void main(String[] args) {
    checkVersion("10.22.5-r");
}

private static void checkVersion(String current) {
    String regex = "([1-9]\\d*)\\.(\\d+)\\.(\\d+)-[b|r](?:[1-9]\\d*)*";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcherCurrent = pattern.matcher(current);
    System.out.println("Matches: " + matcherCurrent.matches());
    System.out.println("The first digit: " + matcherCurrent.group(1));
    System.out.println("The second digit: " + matcherCurrent.group(2));
    System.out.println("The third digit: " + matcherCurrent.group(3));
}

}

edited title
Link
Maksim Dmitriev
  • 1.4k
  • 3
  • 16
  • 29
Loading
Source Link
Maksim Dmitriev
  • 1.4k
  • 3
  • 16
  • 29
Loading