Swift Regex for extracting words between parenthesis

前端 未结 2 1601
难免孤独
难免孤独 2020-12-21 12:11

Hello i wanna extract the text between ().

For example :

(some text) some other text -> some text
(some) some other text      -> some
(12345)          


        
2条回答
  •  甜味超标
    2020-12-21 12:18

    This will work

    \((?=.{0,10}\)).+?\)
    

    Regex Demo

    This will also work

    \((?=.{0,10}\))([^)]+)\)
    

    Regex Demo

    Regex Breakdown

    \( #Match the bracket literally
    (?=.{0,10}\)) #Lookahead to check there are between 0 to 10 characters till we encounter another )
    ([^)]+) #Match anything except )
    \) #Match ) literally
    

提交回复
热议问题