1

I have a string m="hell,hj;nk,.txt"

I want my string as string m="hellhjnk.txt"

I am using:

 Pattern p=Pattern.compile("(\"([^\"]*)(\\.)([a-z]{1,4}[\"]))|'([^']+)(\\.)([a-z]{1,4})'");

It is working for double quotes and extension. How it will work for removing space,comma,semicolon?

1 Answer 1

3

You could just do:

m = m.replaceAll("[,; ]","");

The Pattern class is used for matching. You can essentially do the same thing:

     Pattern p = Pattern.compile("[;, ]");
     String m = "hell,hj;nk,.txt";
     Matcher matcher = p.matcher(m);
     System.out.println(matcher.replaceAll(""));
Sign up to request clarification or add additional context in comments.

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.