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 = ", "");
ROMANIA_engineer
57.1k30 gold badges211 silver badges207 bronze badges
asked Apr 13, 2012 at 11:02
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"
answered Apr 13, 2012 at 11:07
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.

answered Apr 13, 2012 at 11:07

Comments

0
String file_name = newLine3.replaceAll("name\\s+=\\s+", ""); 
answered Apr 13, 2012 at 11:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.