0

I would like to know if anyone knows the regex command to remove the following

 name = 

from the following

 name = wlr

leaving only

 wlr

these details are taken from a txt file but the name = part can appear multiple times

So I was thinking something like this would work but it doesn't work properly

 String file_name = newLine3.replaceAll("name = ", "");
7
  • Could you post a complete example of your input? Commented Apr 13, 2012 at 11:04
  • 2
    some example for "but it doesnt work properly" ? Commented Apr 13, 2012 at 11:05
  • May be a space issue. try "name\\s*=\\s*" Commented Apr 13, 2012 at 11:06
  • Your code works properly, the issue is somewhere else. Commented Apr 13, 2012 at 11:10
  • Please explain "doesn't work properly" as it seems to work for me. Commented Apr 13, 2012 at 11:10

3 Answers 3

1
String newLine3 = "name = wlr";
String fileName = newLine3.replaceAll("name = ", ""); //fileName = "wlr"
Sign up to request clarification or add additional context in comments.

Comments

1

How about:

String input = "name = wlr";
String file_name = newLine3.substring(input.indexof("=") + 1).trim();

Regex seems like overkill for this issue.

Comments

0
String file_name = newLine3.replaceAll("name\\s+=\\s+", ""); 

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.