Reputation: 9134
String str = "abcde123_92qwq_1a_02x_1e";
I want to replace the first string part between the first two underscores (92qwq) with 0 (zero). How can I do this with regex?
For example:
"abcde123_92qwq_1a_02x_1e" becomes "abcde123_0_1a_02x_1e"
"abcde123_sdet4_1a_02x_1e" becomes "abcde123_0_1a_02x_1e"
I'm a newbie to the regex and I have tried a few. But I'm in a kind of bit urgent situation.
Upvotes: 0
Views: 84
Reputation: 33908
You can use something like:
str = str.replaceFirst("_[^_]+_", "_o_");
Upvotes: 3