Regex for extracting 3 digits numbers between brackets

前端 未结 3 1681
攒了一身酷
攒了一身酷 2021-01-28 05:12

My string is:

Frequency/FA ID VerifiedFA0 FAID5(125)/FA1 FAID7(175)/FA2 FAID1(476)

The regex I\'m trying to create should extract these numbers

3条回答
  •  故里飘歌
    2021-01-28 05:37

    Rather than replacing everything that you don't need, you can use Pattern and Matcher class, to extract what you need.

    The regex pattern to extract numbers between brackets would be: -

    \(\d+\)
    

    + quantifier is used to match 1 or more repetition of digits. If you want to match just 3 digits, then you can use {3} quantifier with \d: - \(\d{3}\).

    You can apply this regex pattern with Matcher#find() method to get all the numbers from that string. I leave the task of implementation to you.

提交回复
热议问题