Regex split string preserving quotes

前端 未结 2 1557
走了就别回头了
走了就别回头了 2020-12-05 06:07

I need to split a string like the one below, based on space as the delimiter. But any space within a quote should be preserved.

research library \"not availa         


        
2条回答
  •  孤城傲影
    2020-12-05 06:27

    Here you go:

    C#:

    Regex.Matches(subject, @"([^\s]*""[^""]+""[^\s]*)|\w+")
    

    Regular expression:

    ([^\s]*\"[^\"]+\"[^\s]*)|\w+
    

提交回复
热议问题