java replaceAll(regex, replacement) regex command

徘徊边缘 提交于 2019-12-25 03:24:35

问题


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 = ", "");

回答1:


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



回答2:


String newLine3 = "name = wlr";
String fileName = newLine3.replaceAll("name = ", ""); //fileName = "wlr"



回答3:


How about:

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

Regex seems like overkill for this issue.



来源:https://stackoverflow.com/questions/10139623/java-replaceallregex-replacement-regex-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!