Ragu Ragu - 1 year ago 76
Java Question

Create a regex for following scenerio

In Java, I have a constant string "Transform for {0} unavailable" but when its come through the code it will look like following string

Transform for c5d2f185503a11e68f4dd4bed9c2c707 unavailable

Transform for c5d2f189503a11e68f4dd4bed9c2c707 unavailable

Transform for c5d2f18b503a11e68f4dd4bed9c2c707 unavailable

Transform for b3fe22d1543711e6afb7d4bed9c2c707 unavailable

Bold letters are random value (Only char and number). Can someone help me to create a regex by ignoring the random numbers?

Answer Source

You can use regex Transform\s+for(.*)unavailable

Demo here

Java :

public static void main (String[] args) throws java.lang.Exception
    Pattern p= Pattern.compile("Transform\\s+for(.*)unavailable");
    String s = "Transform for c5d2f185503a11e68f4dd4bed9c2c707 unavailable";

    Matcher m = p.matcher(s);
    if ( m.find() )
        System.out.println("Found match : " + m.group(1));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download