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
AlanF
1,6013 gold badges15 silver badges21 bronze badges
-
Could you post a complete example of your input?Guillaume Polet– Guillaume Polet2012年04月13日 11:04:09 +00:00Commented Apr 13, 2012 at 11:04
-
2some example for "but it doesnt work properly" ?Betlista– Betlista2012年04月13日 11:05:27 +00:00Commented Apr 13, 2012 at 11:05
-
May be a space issue. try "name\\s*=\\s*"Prince John Wesley– Prince John Wesley2012年04月13日 11:06:55 +00:00Commented Apr 13, 2012 at 11:06
-
Your code works properly, the issue is somewhere else.Sergey Kalinichenko– Sergey Kalinichenko2012年04月13日 11:10:05 +00:00Commented Apr 13, 2012 at 11:10
-
Please explain "doesn't work properly" as it seems to work for me.John B– John B2012年04月13日 11:10:13 +00:00Commented Apr 13, 2012 at 11:10
3 Answers 3
String newLine3 = "name = wlr";
String fileName = newLine3.replaceAll("name = ", ""); //fileName = "wlr"
answered Apr 13, 2012 at 11:07
assylias
330k84 gold badges680 silver badges806 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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
John B
33.1k8 gold badges80 silver badges100 bronze badges
Comments
String file_name = newLine3.replaceAll("name\\s+=\\s+", "");
answered Apr 13, 2012 at 11:09
Prince John Wesley
63.9k12 gold badges90 silver badges95 bronze badges
Comments
lang-java