Match Sequence using RegEx After a Specified Character

前端 未结 3 912
温柔的废话
温柔的废话 2020-12-05 13:46

The initial string is [image:salmon-v5-09-14-2011.jpg]

I would like to capture the text \"salmon-v5-09-14-2011.jpg\" and used GSkinner\'s RegEx Tool

相关标签:
3条回答
  • 2020-12-05 14:14

    Use a look-behind:

    (?<=:)[\w+.-]+
    

    A look-behind (coded as (?<=someregex)) is a zero-width match, so it asserts, but does not capture, the match.

    Also, your regex may be able to be simplified to this:

    (?<=:)[^\]]+
    

    which simply grabs anything between (but not including) a : and a ]

    0 讨论(0)
  • 2020-12-05 14:28

    If you are always looking at strings in that format, I would use this pattern:

    (?<=\[image:)[^\]]+
    

    This looks behind for [image:, then matches until the closing ]

    0 讨论(0)
  • 2020-12-05 14:32

    You have the correct regex only the tool you're using is highlighting the entire match and not just your capture group. Hover over the match and see what "group 1" actually is.

    If you want a slightly more robust regex you could try :([^\]]+) which will allow for any characters other than ] to appear in the file name portion.

    0 讨论(0)
提交回复
热议问题