Regex to match a string after colon

后端 未结 4 1813
长情又很酷
长情又很酷 2020-12-03 12:36

Input string is something like this: OU=TEST:This001. We need extra \"This001\". Best in C#.

4条回答
  •  时光取名叫无心
    2020-12-03 13:38

    if the OU=TEST: is your requirement before the string you want to match, use this regex:

    (?<=OU\s*=\s*TEST\s*:\s*).*
    

    that regex matches any length of text after the colon, whereas any text before the colon is just a requirement.

    You can replace TEST with [A-Za-z]+ to match any text other than TEST, or you can replace TEST with [\w]+ to match any length of any combination of alphabet and numbers.

    \s* means it might be any number of whitespaces or nothing in that position, remove it if you don't need such a check.

提交回复
热议问题