1

There is a string in log file like that :

'AUR   HALAA /PART="CMF1_SAS_PROJECT" /ROLE="VR_ANALYST" /TY=C /CAP=S /DEL' (S) 

'AUR and /ROLE="" are a constant part

HALAA and VR_ANALYST are inputs

My Regex is : "^'AUR (\\w+) .*? /ROLE=\"(\\w+)\".*$";

But it doesn't work correctly. Could some one show me the correct regex for this sentence please ?

2
  • 3
    here is online regex tester. Try to experiment there. regexpal.com Commented Oct 21, 2013 at 12:53
  • In addition to @Antoniossss I can also recommend regexplanet.com Commented Oct 21, 2013 at 13:06

2 Answers 2

2

It seems that there is more than one space after 'AUR - you need to allow the regex to match that, too:

"^'AUR +(\\w+) .*? /ROLE=\"(\\w+)\".*$";

You should use the .find() method, not matches(), because your string (if it's from a logfile) likely contains a newline at the end, and the .* won't match that. Plus, the anchors would be unnecessary in that case. So, try this:

Pattern regex = Pattern.compile("^'AUR +(\\w+) .*? /ROLE=\"(\\w+)\".*$");
Matcher regexMatcher = regex.matcher(strLine);
if (regexMatcher.find()) {
    first = regexMatcher.group(1);
    second = regexMatcher.group(2); 
} 
Sign up to request clarification or add additional context in comments.

7 Comments

When I try your regex without parameters like "^'AUR +(HALAA) .*? /ROLE=\"(VR_ANALYST)\".*$" It is still doesn't match :/
The regex does match. You might be using it wrong. How are you performing the match?
String reg = "^'AUR +(HALAA) .*? /ROLE=\\\"(VR_ANALYST)\\\".*$"; Pattern regex = Pattern.compile(reg); if(regex.matcher(strLine).matches())
OK, and how are you performing the match? So far, you've only compiled a regex, not used it.
I forget to added on that part, I editted my previous comment and also add that part to here. if(regex.matcher(strLine).matches())
|
0

Try this ..

^'AUR\s*\w*.*/ROLE="\w*".*

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.