regex to match non-whitespace OR space prefixed with '\\'

后端 未结 3 1772
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-14 15:08

I have a space delimited list of files names, where spaces in the file names are prefixed by \'\\\'

e.g. \"first\\ file second\\ file\"

How can I get my rege

3条回答
  •  不思量自难忘°
    2021-01-14 15:39

    (\S|(?<=\\) )+
    

    Explanation:

    You are looking for either non white-space characters (\S) or a space preceded by a backslash, multiple times.

    All matches will be saved to mach group 1, apply the pattern globally to get all matches in the string.

    EDIT

    Thinking about it, you would not even need capturing to a sub-group. The match alone will be enough, so this could be a tiny bit more efficient (the ?: switches to a non-capturing group):

    (?:\S|(?<=\\) )+
    

提交回复
热议问题