How to increment numeric part of a string by one?

前端 未结 5 1589
耶瑟儿~
耶瑟儿~ 2020-12-11 01:39

I have a string formed up by numbers and sometimes by letters.

Example AF-1234 or 345ww.

I have to get the numeric part and incre

5条回答
  •  粉色の甜心
    2020-12-11 01:50

    Here's some Python code that does what you ask. Not too great on my PHP, but I'll see if I can convert it for you.

    >>> import re
    >>> match = re.match(r'(\D*)(\d+)(\D*)', 'AF-1234')
    >>> match.group(1) + str(int(match.group(2))+1) + match.group(3)
    'AF-1235'
    

提交回复
热议问题