正则表达式在 javascript 中匹配 SVG 路径数据
var string = "M-84.1487,-15.8513 a22.4171,22.4171 0 1 0 0,31.7026 h168.2974 a22.4171,22.4171 0 1 0 0,-31.7026 Z";
var regex = "[a-zA-Z][0-9, /-/.]*";
var array = string.match(regex);
任何人都可以帮助我使用正则表达式来匹配各个指令 (array[0] == "M-84.1487,-15.8513"; array[1] == "a22.4171,22.4171 0 1 0 0,31.7026" ;
)
非常感谢
var string = "M-84.1487,-15.8513 a22.4171,22.4171 0 1 0 0,31.7026 h168.2974 a22.4171,22.4171 0 1 0 0,-31.7026 Z";
var regex = "[a-zA-Z][0-9, /-/.]*";
var array = string.match(regex);
Can anyone help me with my regular expression to match individual intructions (array[0] == "M-84.1487,-15.8513"; array[1] == "a22.4171,22.4171 0 1 0 0,31.7026";
)
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 BNF 描述,您可以将指令识别为后面跟着的字母任何非字母的东西。
当然,您可能想要修剪结果,但这应该不会太难。
另外,尽量不要将变量命名得如此无意义(
string
、regex
、array
)。在我看来,这比将它们命名为a
、b
或c
更糟糕。According to the BNF description you can identify an instruction as a letter followed by anything that is not a letter.
Of course you may want to trim the results, but that shouldn't be too hard.
Also try not to name your variables so meaningless (
string
,regex
,array
). In my opinion that's worse than naming thema
,b
orc
.