How to use regex with optional characters in python?

后端 未结 5 676
离开以前
离开以前 2020-12-01 12:12

Say I have a string

\"3434.35353\"

and another string

\"3593\"

How do I make a single regular expression

5条回答
  •  抹茶落季
    2020-12-01 12:28

    Use the "one or zero" quantifier, ?. Your regex becomes: (\d+(\.\d+)?).

    See Chapter 8 of the TextWrangler manual for more details about the different quantifiers available, and how to use them.

提交回复
热议问题