- 论坛徽章:
- 11
|
回复 1# good_luck_68
楼上已经提供多种解决办法了,主要留意下backreferences的用法,见Python文档- \number
- Matches the contents of the group of the same number. Groups are numbered starting from 1. For example, (.+) \1 matches 'the the' or '55 55', but not 'the end' (note the space after the group). This special sequence can only be used to match one of the first 99 groups. If the first digit of number is 0, or number is 3 octal digits long, it will not be interpreted as a group match, but as the character with octal value number. Inside the '[' and ']' of a character class, all numeric escapes are treated as characters.
复制代码 \number的合法值为1~99,如果‘\’后有0或3个数字,则按照8进制字符串解释因此会有你上面的”J3DEFG“
字符串操作简单直观最好,一般最后一招才是正则表达式,能用定长({})匹配就不用变长(*, +),推荐看下《OReilly.Mastering.Regular.Expressions.3rd.Edition》
|
|