Regular expression for extracting a number

后端 未结 4 1647
不思量自难忘°
不思量自难忘° 2020-12-22 08:45

I would like to be able to extract a number from within a string formatted as follows:

\"<[1085674730]> hello foo1, how are you doing?\"

I\'m a novice wit

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 08:53

    Use:

    <\[(\d+)\]>
    

    This is tested with ECMAScript regex.

    It means:

    • \[ - literal [
    • ( - open capturing group
    • \d - digit
    • + - one or more
    • ) - close capturing group
    • \] - literal ]

    The overall functionality is to capture one or more digits surrounded by the given characters.

提交回复
热议问题