I would like to convert a string so that all numeric subsequences are enclosed in a {…} pair.
For instance:
input_string = "APPL[E]5XXXX"
output_string = "APPL[E]{5}XXXX"
Each string may contain one or more digits, for instance BASIC76XXXXX98ZZZZ and output should be BASIC{76}XXXXX{98}zzzz
Not sure if this possible to achieve. Any help will be very much appreciated.
This is for sure possible.
You want a regex that matches on digits, captures the digits, then substitutes the match with a wrapped set of curly braces.
\d+matches digits.()captures and stores in$1.s///is a substitution regex./gat the end means ‘global’, aka, do this for all matches.