相关疑难解决方法(0)

格式化数字与特定掩码正则表达式python

我需要使用特定的掩码格式化数字:9.9.9.9.99.999,具体取决于数字字符串的长度.
例如:

- 123456789 => 1.2.3.4.56.789
- 123456    => 1.2.3.4.56
- 1234      => 1.2.3.4
- 123       => 1.2.3
- 12        => 1.2
Run Code Online (Sandbox Code Playgroud)

它不会出现输入中带有7或8位数字的数字字符串.

如何使用正则表达式实现,最好是在python中?

提前致谢.

python regex format mask string-formatting

6
推荐指数
2
解决办法
1457
查看次数

标签 统计

format ×1

mask ×1

python ×1

regex ×1

string-formatting ×1