Regex 使用正则表达式模式进行替换

Regex 使用正则表达式模式进行替换,regex,pandas,Regex,Pandas,我在一列中有一些包装尺寸,如 1x10 20x30 200 x 10 你想把它换成什么 1 X 10 20 X 30 200 X 10 有可能用这样的模式替换值吗 units.replace('\d{1,4}[xX]\d{1,4}','\d{1,4}\s[X]\s\d{1,4}', regex=True) 错误 使用带有反向引用的捕获组units.str.replace(r'(\d{1,4})([xX])(\d{1,4}'),r'\1\2\3',regex=True) bad escape

我在一列中有一些包装尺寸,如

1x10
20x30
200 x 10
你想把它换成什么

1 X 10
20 X 30
200 X 10
有可能用这样的模式替换值吗

units.replace('\d{1,4}[xX]\d{1,4}','\d{1,4}\s[X]\s\d{1,4}', regex=True)
错误


使用带有反向引用的捕获组
units.str.replace(r'(\d{1,4})([xX])(\d{1,4}'),r'\1\2\3',regex=True)
bad escape \d