0

On regex101.com I used the following expression which returned a ':' and a number (e.g. ':15').

(?<=Total)(\s*\:\s*)\d{1,3}(?=h)

These are string examples:

Anne KowalskyTotal:15hPersonal data

2021-01-19Total: 2hCertificate

Unfortunately, my RegEx doesn't return a match with C#. I also tried runnig the RegEx method in C# with Multiline option but this also didn't work.

What do I need to do in order to make it work?

annyka
  • 71
  • 5
  • 3
    Can you add the code to the question? – The fourth bird Jan 22 '21 at 15:08
  • 1
    `@"(?<=Total)(\s*\:\s*)\d{1,3}(?=h)"` put a @ before the "..." if you haven't already done it – xanatos Jan 22 '21 at 15:08
  • 3
    Regex101.com [generates code for you](https://regex101.com/r/gLySzX/1/codegen?language=csharp). Also, you may just use `(?<=Total\s*\:\s*)\d{1,3}(?=h)` to get the number only in the match value in C#. – Wiktor Stribiżew Jan 22 '21 at 15:09
  • 1
    @WiktorStribiżew Was just about to say that there is a code generator to generate code for a number of languages including C# – phuzi Jan 22 '21 at 15:10
  • 1
    Your regular expression returns ":15" and ": 2" for me. The [Multiline option](https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regexoptions?view=net-5.0#System_Text_RegularExpressions_RegexOptions_Multiline) shouldn't make any difference, since you are not using `^` or `$` – Olivier Jacot-Descombes Jan 22 '21 at 15:16

0 Answers0