Extract values between parenthesis from NSString

后端 未结 4 862
一整个雨季
一整个雨季 2021-02-09 21:56

I have an NSString that will be something like \"xxxx (yyyyy)\" where x and y can be any character. I\'d like to extract just the y from inside the parenthesis. I managed to ext

4条回答
  •  孤独总比滥情好
    2021-02-09 22:17

    Easiest way would be to use RegExKit:

    http://regexkit.sourceforge.net/

    Then you'd do something like:

    [@"xxxx(yyyyy)" getCapturesWithRegexAndReferences:@"\\((.*)\\)",@"$1", &extractedString,nil];
    

    and extractedString would contain whatever was in parenthesis.

提交回复
热议问题