Regex C++: extract substring

前端 未结 4 1067
陌清茗
陌清茗 2020-12-02 23:13

I would like to extract a substring between two others.
ex: /home/toto/FILE_mysymbol_EVENT.DAT
or just FILE_othersymbol_EVENT.DAT
And I

4条回答
  •  [愿得一人]
    2020-12-02 23:51

    TRegexp only supports a very limited subset of regular expressions compared to other regex flavors. This makes constructing a single regex that suits your needs somewhat awkward.

    One possible solution:

    [^_]*_([^_]*)_
    

    will match the string until the first underscore, then capture all characters until the next underscore. The relevant result of the match is then found in group number 1.

    But in your case, why use a regex at all? Just find the first and second occurrence of your delimiter _ in the string and extract the characters between those positions.

提交回复
热议问题