How to use regex non capturing group for string replace in java -


i had requirement change assemblyversion on new build. using java code string.replaceall(regexpattern,updatedstring);

this code works fine normal regex patterns, not able use non-capturing groups in pattern. want use non-capturing groups make sure don't capture patterns other required one. code tried:

string str="[assembly: assemblyversion(\"1.0.0.0\")]"; str=str.replaceall("(?:\\[assembly: assemblyversion\\(\"\\d\\.\\d\\.)?.*(?:\"\\)\\])?", "4.0"); system.out.println(str); 

here, want match string [assembly: assemblyversion(int.int , replace minor version.

expected outcome [assembly: assemblyversion("1.0.4.0")], i'm getting result 4.04.0.

can please me on this?

why not use looka-head / look-behind instead?

they non-capturing , work here:

str = str     .replaceall(         "(?<=\\[assembly: assemblyversion\\(\"\\d\\.\\d\\.).*(?=\"\\)\\])",               "4.0"     ); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -