What is a regex to match ONLY an empty string?

后端 未结 10 1656
忘掉有多难
忘掉有多难 2020-12-01 13:24

There are lots of posts about regexs to match a potentially empty string, but I couldn\'t readily find any which provided a regex which only matched an emp

10条回答
  •  借酒劲吻你
    2020-12-01 14:26

    Another possible answer considering also the case that an empty string might contain several whitespace characters for example spaces,tabs,line break characters can be the folllowing pattern.

    pattern = r"^(\s*)$"

    This pattern matches if the string starts and ends with zero or more whitespace characters.

    It was tested in Python 3

提交回复
热议问题