Match a regex and reverse the matches within the target string
问题 Based on this question Regex \d+(?:-\d+)+ will match this 10-3-1 and 5-0 . Example: This is 10-3-1 my string After performing the matching and reversing, I want it to be like this: This is 1-3-10 my string Notice that 10-3-1 should become 1-3-10 and not normal string reverse which would result in 1-3-01. 回答1: A basic algorithm would be: Extract the match from the string. "10-3-1" Split the match into a segments by the "-" character. You now have a list of elements. ["10","3","1"] Reverse the