提取数字串

时间:2016-06-24 03:06:03

标签: regex jira

我正在尝试在JIRA中设置邮件处理程序。我有以下可能的格式,我需要确保字符串包含Case [number] - New Comment Added

因此对于以下内容,它应该返回123456(可能是更多数字,但数字之间没有空格)

RE: Vendor Support Case 123456 - New Comment Added
Case 123456 - New Comment Added

2 个答案:

答案 0 :(得分:4)

这是一个选项,它也可以在数字之前和之后找到字符串,但不会使它们成为匹配的一部分:

#include <stdio.h>
#include <cs50.h>
int main(void)
{
  char choices;
  float math, pc, svt, eng, philo;
  do 
  {      
    // Other code here

    int choice = GetInt();
    if(choice == 1){
         float score = (math*7 + pc*7 + svt*7 + eng*2 + philo*2)/25;
         printf("Your score is %.2f\n", score);
    }
    else if(choice == 2){
        float score = (math*9 + pc*7 + svt*3+ eng*2 + philo*2)/23;
        printf("Your score is %.2f\n", score);
    }
    else{
        printf("You've picked the wrong choice \n");
        choices = 'Y';

    }

    if ((choice == 1) || (choice == 2))
    {
      printf("Do you want to try it again? (Y/N) ");
      choices = getchar();
      while (choices != '\n' && getchar() != '\n') {};
    }
  } while (choices == 'Y' || choices == 'y');
}

(?:Case\s*)(\d+)(?: - New Comment Added) 是正则表达式中的非捕获组 - 即它找到字符串,但它会丢弃它并且不会将其添加到最终结果中。注意不要在它周围添加一对括号,因为它会捕获它并使其成为最终匹配的一部分。

答案 1 :(得分:0)

如果您的工具支持环视:

(?<=Case )\d+(?= - New Comment Added)

整场比赛是你的案件编号。如果您不需要(?= - New Comment Added)来跟踪该号码,则可以删除" - New Comment Added"

相关问题