Parsing formatted string

前端 未结 6 768
渐次进展
渐次进展 2020-12-03 14:12

I am trying to create a generic formatter/parser combination.

Example scenario:

  • I have a string for string.Format(), e.g. var format = \"{0}-{1}\
6条回答
  •  清歌不尽
    2020-12-03 14:20

    A simple solution might be to

    • replace all format tokens with (.*)
    • escape all other special charaters in format
    • make the regex match non-greedy

    This would resolve the ambiguities to the shortest possible match.

    (I'm not good at RegEx, so please correct me, folks :))

提交回复
热议问题