objective c - NSRegularExpression - Probleme with a Pattern -
objective c - NSRegularExpression - Probleme with a Pattern -
i've wrote little programme find string in string works fine far. have problem nsregularexpression - need right pattern special case , stuck.
nsstring *strregexp = [nsstring stringwithformat:@"?trunk/%@/%@/+\\([a-za-z0-9_\\-\\.])+/host-1", inputstrse , inputstrsno]; nsregularexpression *regex = [nsregularexpression regularexpressionwithpattern:strregexp options: nsregularexpressioncaseinsensitive error:null]; nsarray *arrayofallmatches = [regex matchesinstring:inputurl options:0 range:nsmakerange(0, [inputurl length])];
the nsregularexpression pattern should match string this:
trunk/%@/%@/some-text-1/host-1 trunk/test/1/5-text-text/host-1
where trunk/%@/%@/ , /host-1 stays same. part in middle variable , looks this:
number-some-text -> 5-hello-world -> /trunk/test/1/5-hello-world/host-1
i've tried different regexp see here: "?trunk/%@/%@/+\([a-za-z0-9_\-\.])+/host-1", still seems not work, maybe can help me.
maybe there probleme when build pattern with:
nsstring *strregexp = [nsstring stringwithformat:@"?trunk/%@/%@/+\\([a-za-z0-9_\\-\\.])+/host-1", inputstrse , inputstrsno];
and utilize later that:
regularexpressionwithpattern:strregexp
i hope can help me - i'm new regularexpressions.
generally, expressing regex "i want match number of letters, dash, number" , on easiest way build one. also, using tool such http://www.regexr.com simplifies lot.
from understand want match following:
trunk/test/1/[some number]-[some text]-[some other text]/host-1
if so, next regular look should cutting it:
trunk\/test\/1\/[0-9]*-[a-za-z]*-[a-za-z]*\/host-1
it following:
trunk\/test\/1\/
: match constant string trunk/test/1/
(the backslashes escapes) [0-9]*-
: match number of digits followed -
[a-za-z]*-
: match number of letters followed -
[a-za-z]*
: match number of letters \/host-1
: match constant string /host-1/
here link regexr can utilize if want experiment different input info or changes regex: http://regexr.com/39tgn
the next string provided in comments: trunk\test\/1\/.*\/host-1
. it's bit less strict job well.
objective-c regex nsstring nsregularexpression
Comments
Post a Comment