0

I have this input:

;Client = tefexx;Test = tgrfdrff;Piemel = thgfress

And this regex:

(;Client = )

The word in the regex would change depending on the needs. But in this case I would want to only return tefexx. I don't understand how to match just that word.

3 Answers 3

2

You can try this :

(;Client = (.*?);)

In your exemple, this regexp's second capturing group will hold 'tefexx' only.

Sign up to request clarification or add additional context in comments.

Comments

0

This should work /Client = ([a-zA-z]+);/

Comments

0

Here's an example using Pattern and Matcher:

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

public class Re {
    static String s = ";Client = tefexx;Test = tgrfdrff;Piemel = thgfress";
    static String re = ";Client = ([^;]*);";

    static public void main(String[] args) {
        Pattern pattern = Pattern.compile(re);
        Matcher matcher = pattern.matcher(s);
        if (matcher.find()) {
            System.out.println(matcher.group(1));
        }
    }
}


$ java Re
tefexx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.