Looking at the code directly, I can probably understand the requirements I need to complete.
I need to be here|
The last group of sign segmentation is replaced with its corresponding Chinese representation (of course, there is a corresponding one here)key-value
Dictionary).
bs.replace(/([^\|]*)$/, function(key){return map[key];});
So inJava
How to realize it?
String str = "abcd|substr";
/*1. This method doesn't support regular expressions, just simple character (string) replacement*/
String ret = str.replace ("[^ \ \ |] * $", "replacement");
System.out.println(ret); // abcd|substr
/*2. Examples of failure*/
ret = str.replaceAll ("[^ \ \ |] * $", "replacement");
System.out.println (RET); // ABCD | replace
/*3. New ideas*/
ret = str.replaceFirst ("(. * \ \ |) (. *) $", "$1 replacement");
System.out.println (RET); // ABCD | replace