简体   繁体   English

REGEX从图像文件名获取元素

[英]REGEX to get the elements from the image filename

I need to parse a set of filenames with the next pattern: 我需要使用下一个模式解析一组文件名:

A0001L+23.20K+01-Red.JPG A0001L + 23.20K + 01-Red.JPG

Into the followed elements: 分为以下元素:

  • Get the first Number -> 0001 获取第一个数字-> 0001
  • Get the L value -> 23.20 (Could be positive or negative number) 获取L值-> 23.20(可以为正数或负数)
  • Get the K value -> 01 (Could be positive or negative number) 获取K值-> 01(可以是正数或负数)
  • Get the color -> Red 获取颜色->红色

I'm using the the approach of REGEX groups using the next pattern: 我使用下一个模式使用REGEX组的方法:

IMAGE_PATTERN = "[A-Z](\\d\\d\\d\\d)[A-Z][-|\\+](\\d\\d\\.\\d\\d)[A-Z][-|\\+](\\d\\d)-([A-Za-z]+)(\\.[A-Za-z]+)";

But is not working correctly, is the IMAGE_PATTERN, set it right? 但是无法正常工作,IMAGE_PATTERN是否设置正确?

I have tested below pattern and it works: 我已经测试了以下模式,它的工作原理:

[a-zA-Z]([0-9]{4})L\+([0-9\.]+)K([+\-][0-9]+)\-([a-zA-Z]+)

You can modify it to suit your needs. 您可以对其进行修改以适合您的需求。

You may check out the below link 您可以查看以下链接

Regex101Link 正则表达式101链接

I think you are after this, includes fetching +/- as well 我想您是在这之后,还包括提取+/-

[a-zA-Z](\d{4})[A-Z]([+\-]\d{2}\.\d{2})K([+\-][0-9]+)\-([a-zA-Z]+)

Regex Test Link 正则表达式测试链接

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM