Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex string match uuid beetwin the words

How to write regex that will be matches to this string

Received request with messageId:test, clientId:7da6554c-e3ed-49ed-9a7f-f810f98ceb7f has been processed

uuid will be always different

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

so i want to check some big text and if it contains

Received request with messageId:test, clientId:some uuid has been processed

bigText.matches(regex) == true

>Solution :

You can use this regex to match the specified string pattern

Received request with messageId:test, clientId:[\\w-]+ has been processed

Full code for Java language :

import java.util.regex.*;

public class Main {
    public static void main(String[] args) {
        // Your larger text
        String largerText = "Received request with messageId:test, clientId:7da6554c-e3ed-49ed-9a7f-f810f98ceb7f has been processed";

        // Define the regular expression pattern
        String pattern = "Received request with messageId:test, clientId:[\\w-]+ has been processed";

        // Create a Pattern object
        Pattern regex = Pattern.compile(pattern);

        // Create a Matcher object
        Matcher matcher = regex.matcher(largerText);

        // Check if a match was found
        if (matcher.find()) {
            String matchedText = matcher.group();
            System.out.println("Match found: " + matchedText);
        } else {
            System.out.println("No match found");
        }
    }
}

Output :

Match found: Received request with messageId:test, clientId:7da6554c-e3ed-49ed-9a7f-f810f98ceb7f has been processed

Explanation:

pattern : is the regular expression pattern that looks for the fixed part "Received request with messageId:test, clientId:" followed by one or more word characters (\w) and hyphens (-) for the UUID.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading