AlanF
AlanF

Reputation: 1601

java replaceAll(regex, replacement) regex command

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

Upvotes: 0

Views: 477

Answers (3)

Prince John Wesley
Prince John Wesley

Reputation: 63688

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

Upvotes: 0

John B
John B

Reputation: 32949

How about:

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

Regex seems like overkill for this issue.

Upvotes: 1

assylias
assylias

Reputation: 328598

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

Upvotes: 1

Related Questions