1

I'm trying to turn, a/b/c.x.y into abc. However there seems to be an issue with my regular expression, specifically with '\\.*'.

 "a/b/c.x".replaceAll( "/|\\.*", "" );

yields:

 "abcx"

Any insight would be great, thanks!

1
  • Is that the only format it will ever be in? Because a/b.x/c would require some different logic. Commented Aug 24, 2012 at 15:41

2 Answers 2

6

You're replacing any slash or "any number of dots" with an empty string.

I suspect you mean any slash or "a dot followed by any number of any characters" which would be:

replaceAll("/|\\..*", "");

That certainly works for me with the sample value.

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

1 Comment

Just what I was typing. Rule isn't clear from the question, but the * implies this is what the OP was after.
0

Your current regex matches a forward slash OR zero or more periods. I assume that you want to match forward slash OR a period plus anything after it. For that, you want

"/|\\..*"

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.