2016-03-02 2 views
1

J'ai une chaîne d'étiquettes html dans laquelle je suis à la recherche d'un modèle particulier - Il devrait être "suivi" qui peut être suivi par l'espace, caractère deux points ou de nouvelles lignes, suivies d'un nombre compris entre 8 et 13 chiffres.Expression régulière, Rechercher un motif de chaîne, nombre et espaces blancs newline

J'utilise ci-dessous Expression régulière pour savoir ce modèle

NSString * FollowUp = @ » Suivi 614233222 Suivi S'il vous plaît inlcude la ligne ci-dessous dans le suivi des balises où le suivi \ n: 123212323 567 Suivi 1234231234 qui doit être ignoré avec 123 < \ n> Veuillez inclure la ligne ci-dessous dans les courriels de suivi pour cette demande: < \ n> < \ n> ";

NSString *pattern = [NSString stringWithFormat:@"Follow-up(\\s|:)*\\d{8,13}"]; 

    NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:pattern 
                      options:NSRegularExpressionCaseInsensitive 
                       error:NULL]; 

    [regExp enumerateMatchesInString:followUp 
           options:0 
            range:NSMakeRange(0, followUp.length) 
          usingBlock:^(NSTextCheckingResult * _Nullable result, NSMatchingFlags flags, BOOL * _Nonnull stop) { 
           NSString * foundMatch = [followUp substringWithRange:[result rangeAtIndex:0]]; 
           NSLog(@"found is %@",foundMatch); 
          }]; 

Le résultat est donné mais il ne donne pas tous les résultats correspondants. Quelqu'un peut-il m'aider s'il vous plaît ce que je fais mal ici.

Répondre

0

Essayez cette

Follow-up[\s\n\\n:]+[\d]{8,13}

Regex101 Demo

NSString *pattern = [NSString stringWithFormat:@"Follow-up[\\s\\n\\\\n:]+([\\d]{8,13})"]; 
NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:nil]; 
[regExp enumerateMatchesInString:followUp 
         options:0 
          range:NSMakeRange(0, followUp.length) 
         usingBlock:^(NSTextCheckingResult * _Nullable result, NSMatchingFlags flags, BOOL * _Nonnull stop) { 
          NSString * foundMatch = [followUp substringWithRange:[result rangeAtIndex:1]]; 
          NSLog(@"found is %@",foundMatch); 

NSLog:

found is 614233222 
found is 123212323 
found is 1234231234 
+0

Merci! C'était ça. – Hanisha