【发布时间】:2011-05-09 07:08:46
【问题描述】:
我在 django/python 应用程序中有一个字符串,需要在其中搜索 [x] 的每个实例。这包括括号和 x,其中 x 是 1 到几百万之间的任何数字。然后我需要用我自己的字符串替换 x。
也就是说,'Some string [3423] of words and numbers like 9898' 会变成 'Some string [mycustomtext] of words and numbers like 9898'
请注意,只有括号中的数字受到影响。我不熟悉正则表达式,但认为这对我有用吗?
【问题讨论】:
-
我不想这样做,但我想我可以单独处理这种特殊情况
标签: python regex string replace