I am using regex to match
([A-Za-z2-7\/\\ ]{52})
While any string with 52 characters as the one mentioned above will match the string, I want to exclude strings that begin with : followed by the 52 characters.
I am using regex flavor pcre2 For example while the below string matches the regex I wouldn't want to include it since the 52 characters preceed with a :
C:\Users\abcdef\AppData\Local\abcdefghijklmnopqr\Testmeli_fi
CodePudding user response:
Use
:([A-Za-z2-7\/\\ ]{52})(*SKIP)(*F)|(?1)
See regex proof.
EXPLANATION
--------------------------------------------------------------------------------
: ':'
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[A-Za-z2- any character of: 'A' to 'Z', 'a' to
7\/\\ ]{52} 'z', '2' to '7', '\/', '\\', ' ' (52
times)
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
(*SKIP)(*F) fail the match and restart after failure
--------------------------------------------------------------------------------
| or
--------------------------------------------------------------------------------
(?1) recurse group 1 pattern
CodePudding user response:
You could use an anchor to assert the start of the string:
^[A-Za-z2-7\/\\ ]{52}
See a regex demo.
