I'm trying to match fully qualified C# type names, but the after \w captures too much:
global((::|\.)\w (?!\s|\())
Tried to play with quantifiers and negative lookahead but without success.
Online sandbox:
https://regex101.com/r/L6Y8kv/1
Sample:
public global::libebur128.EBUR128StateInternal D
{
get
{
var __result0 = global::libebur128.EBUR128StateInternal.__GetOrCreateInstance(((__Internal*)__Instance)->d, false);
return __result0;
}
Result:
global::libebur128.EBUR128StateInterna
global::libebur128.EBUR128StateInternal.__GetOrCreateInstanc
Expected:
global::libebur128.EBUR128StateInternal
global::libebur128.EBUR128StateInternal
CodePudding user response:
For the example data, you might use:
\bglobal::[^\W_] (?:\.[^\W_] )*
The pattern matches:
\bglobal::A word boundary, followed by matchingglobal::[^\W_]Match 1 word characters excluding_(?:\.[^\W_] )*Optionally repeat matching.and 1 word characters excluding_
See a regex101 demo.
If the last part should not be followed by ( and you don't want to take the underscore into account, you might add a word boundary and a negative lookahead:
\bglobal::\w (?:\.\w )*\b(?!\()
The pattern matches:
\bA word boundaryglobal::Match literally\wMatch 1 word chars(?:\.\w )*Optionally repeat.and 1 word chars\bA word boundary (to prevent backtracking to make the next assertion true)(?!\()Negative lookahead, assert not(directly to the right of the current position
