Hi all,
Couple of questions:
1) How to make the following regex which are based on search literal ^ work for the search literal |
search literal ^ based regex (which works fine, which is one of the valuable inputs from this forum):
String intermediateResult = in.replaceAll( "(TEST\\^[^^]*\\^\\^[^^]*\\^[^^]*\\^)\"\"\\^", "$1^" );
String finalResult = intermediateResult.replaceAll( "(TEST\\^[^^]*\\^)(\\^[^^]*\\^[^^]*\\^([^\"\\^].*|\"[^\"].*))", "$1ST$2" );
When I replace ^ (where ever required) to | as follows - I do not get the desired result(it does not change anything in the given string):
String intermediateResult = in.replaceAll( "(TEST\\|[\\|\\|]*\\|[\\|\\|]*\\|[\\|\\|]*\\|[\\|\\|]*\\|)\"\"\\|", "$1|" );
String finalResult = intermediateResult.replaceAll( "(TEST\\|[\\|\\|]*\\\\|)(\\|[\\|\\|]*\\|[\\|\\|]*\\|([^\"\\^].*|\"[^\"].*))", "$1ST$2" );
Are there any known issues with | in java regex or do I need to have the regex differently for search literal |
So I tried this way but in vain (Having \\| instead of \|):
First regex changes all places that are like |""| in the given string, though I expect it to make it blank only if the content between 5th and 6th occurence of | is "", not sure why. The second regex does not change the string at all for some reason.
String intermediateResult = in.replaceAll( "(TEST\\|[\\|\\|]*\\\\|[\\|\\|]*\\\\|[\\|\\|]*\\\\|[\\|\\|]*\\\\|)\"\"\\|", "$1|" );
String finalResult = intermediateResult.replaceAll( "(TEST\\|[\\|\\|]*\\\\|)(\\\\|[\\|\\|]*\\\\|[\\|\\|]*\\|([^\"\\^].*|\"[^\"].*))", "$1ST$2" );
2) Also what does the match part and replacement str of this regex imply:
String finalResult = intermediateResult.replaceAll( "(TEST\\^[^^]*\\^)(\\^[^^]*\\^[^^]*\\^
**([^\"\\^].*|\"[^\"].*)**)", "**$1ST$2**" );
Any help is highly appreciated
Thanks in advance.