0
String depends2 = "success(job1) AND n(job2)";
depends2  = depends2.replaceAll("[\\s].(?i)[snd][\\s]*\\(", "");     
System.out.println(depends2);

I expect this to output

success(job1) ANDjob2)

Instead it outputs

success(job1) AND n(job2)

1 Answer 1

1

[\\s].(?i)[snd] This in your regex ensures that there must a character present inbetween the space and n (followed by zero or more spaces plus ( symbol). But there isn't a character actually. So your regex fails and returns the original string without doing any replacements.

String depends2 = "success(job1) AND n(job2)";
depends2  = depends2.replaceAll("\\s(?i)[snd]\\s*\\(", "");     
System.out.println(depends2);

Output:

success(job1) ANDjob2)

Explanation:

\s                       whitespace (\n, \r, \t, \f, and " ")
(?i)                     set flags for this block (case-
                         insensitive) (with ^ and $ matching
                         normally) (with . not matching \n)
                         (matching whitespace and # normally)
[snd]                    any character of: 's', 'n', 'd'
\s*                      whitespace (\n, \r, \t, \f, and " ") (0 or
                         more times)
\(                       '('
Sign up to request clarification or add additional context in comments.

1 Comment

You are right of course - my bad i did a typo. I was looking for [\s.](?i)[snd][\s]*( meaning at least one space and I put the . outside :)

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.