Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python正则表达式-清理一些Gcode_Python_Regex_String_G Code - Fatal编程技术网

Python正则表达式-清理一些Gcode

Python正则表达式-清理一些Gcode,python,regex,string,g-code,Python,Regex,String,G Code,我已经为此奋斗了一段时间,希望得到一个提示! 在将Gcode文件发送到3d打印机之前,我正在从Gcode文件中剥离某些元素 我的绳子是 f100G00X345.234Y234F345.5623I-2344.234J234.234F544 或者类似的,我注意匹配(为了删除)字母“F | F”后面跟一个数字(float)的元素,在上面的字符串中,这些元素是: f100 - F345.5623 - F544 我的正则表达式离现在很近 (F|f).*?([^0-9|.]|\Z) 我认为(不确定)

我已经为此奋斗了一段时间,希望得到一个提示! 在将Gcode文件发送到3d打印机之前,我正在从Gcode文件中剥离某些元素

我的绳子是

f100G00X345.234Y234F345.5623I-2344.234J234.234F544
或者类似的,我注意匹配(为了删除)字母“F | F”后面跟一个数字(float)的元素,在上面的字符串中,这些元素是:

f100 - F345.5623 - F544
我的正则表达式离现在很近

(F|f).*?([^0-9|.]|\Z)

我认为(不确定)它找到了F字母,并抓住了所有的数字、点或尾端。但这也包括最后一个字符和上面匹配的刺

f100G - F345.5623I - F544
那么,我该如何舍弃匹配的最后一个字符,或者采用更好的方法


谢谢

您与
*?
模式的匹配太多了。仅匹配数字和点:

[Ff][\d.]+
这将匹配
F
F
类中的一个字符,然后是
\d
类中的一个或多个字符(数字或点)

演示:

请注意,
[^0-9 |.]
负字符类模式也不包括
符号。否定字符类的
[^…]
中的所有内容都被排除。

或者您可以使用拆分:

re.split(r'[^fF\d.][^fF]*', example)
re.split(r'[^fF\d.][^fF]*', example)