0

I'm using a .NET regex checker, http://regexstorm.net/tester

to test a string to match acronyms

(?<=\s|^)((?:[a-zA-Z]\.){2,})(?=[[:punct:]]?(?:\s|$))

Away from keyboard is shortened into A.F.K.

The online tool correctly match A.F.K.

But the C# does not!

var regex = new Regex(@"(?<=\s|^)((?:[a-zA-Z]\.){2,})(?=[[:punct:]]?(?:\s|$))");
var match = regex.Match("Away from keyboard is shortened into A.F.K.");
if(!match.Success)
    throw new NoMatchException("no match found"); // throws
UberFace
  • 385
  • 2
  • 10
  • 1) `[[:punct:]]` does not work as you expect, .NET regex does not support POSIX character classes (to match punctuation and symbols, you need `[\p{P}\p{S}]`, or `(?:_|[^\w\s])`), 2) [your code works in C#](https://ideone.com/jC2m2k) – Wiktor Stribiżew Aug 27 '20 at 08:31
  • that compiler online you tried is .NET 4.7.X, I have net core3.1 and there it don't work, I'll try wwith the other expression – UberFace Aug 27 '20 at 08:35
  • ok `[\p{P}\p{S}]` worked I will accept it as answer if you answer it. Thank you – UberFace Aug 27 '20 at 08:35

0 Answers0