Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to replace any sequence of numbers in a string with the number itself within brackets. So the input:

"i ee44 a1 1222"  

Should have as an output:

"i ee(44) a(1) (1222)"

I am trying to implement it using String.replace(a,b) but with no success.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
967 views
Welcome To Ask or Share your Answers For Others

1 Answer

"i ee44 a1 1222".replaceAll("\d+", "($0)");

Try this and see if it works.

Since you need to work with regular expressions, you may consider using replaceAll instead of replace.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...