Reputation: 379
I have this line in a text file which is in the following format:
/ text
/
I need to edit the line and remove text and have a result like this:
/
/
What regex should I use to remove the text? I have a problem because one "/" is in the line below.
Upvotes: 0
Views: 84
Reputation: 2768
you can use this regexp if line "/" starts and you don't need anything after it:
String in = "/ text\n /";
String pattern = "^(/)(.+?)(\\n.*)";
System.out.println(in.replaceAll(pattern, "$1$3"));
Upvotes: 1
Reputation: 36
If your trying to remove all characters after a "/" you can do:
String in = "/ text\n /";
String out = in.replaceAll("/.*", "/");
Upvotes: 1
Reputation: 68847
How about this?
public String doMagic()
{
return "/\n /";
}
Upvotes: 4