objective c - NSRegularExpression, select part of a string -



objective c - NSRegularExpression, select part of a string -

given string this:

seat 2: pet21 ($1.98 in chips)

in php can select part of regex using parentheses in regex, this:

seat ([0-9]+): (.{1,12}) .[$|€|£]([0-9]+\.?[0-9]{0,2}) in chips.

this selects seat number, user id , amount of chips:

array ( [0] => array ( [0] => seat 1: s@pphir ($0.83 in chips) [1] => seat 2: pet21 ($1.98 in chips) [2] => seat 3: derphurp ($2.76 in chips) [3] => seat 4: -m-a-r-k-qaz ($0.92 in chips) [4] => seat 5: rolle55 ($2.45 in chips) [5] => seat 6: sanderdecler ($2 in chips) ) [1] => array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [2] => array ( [0] => s@pphir [1] => pet21 [2] => derphurp [3] => -m-a-r-k-qaz [4] => rolle55 [5] => sanderdecler ) [3] => array ( [0] => 0.83 [1] => 1.98 [2] => 2.76 [3] => 0.92 [4] => 2.45 [5] => 2 ) )

is there way similar in objective-c nsregularexpression

edit: far i've got this:

nsregularexpression *regex = [nsregularexpression regularexpressionwithpattern:@"seat [0-9]+: (.{1,12}) .[$|€|£][0-9]+\.?[0-9]{0,2} in chips." options:0 error:nil]; (nstextcheckingresult *result in [regex matchesinstring:history options:nsmatchingreportcompletion range:nsmakerange(0, history.length)]) { }

you want utilize firstmatchinstring:options:range: method of nsregularexpression, returns nstextcheckingresult. want utilize rangeatindex: method of nstextcheckingresult range of each submatch. can pass range substringwithrange: method of original nsstring text of submatch.

objective-c regex ios5 nsregularexpression

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -