c# - Exactly one occurrence in regex -
i have regex:
@"\s*[\( \[ \{]\s*[a]\s*[n]\s*[\} \] \)]\s*"
than detects string within 1 opening , closing braces: ( [ {
if there number of spaces in string anywhere.
but problem detects 'an'
if not within braces. how instruct regex observe string 'an' within 1 opening , closing braces.
abc abc
should not match.
i want match string like:
abc [ ] abc abc { n } abc abc ( n ) abc
and can brackets type matched? mean possible match have closing bracket same opening bracket?
try removing spaces in square brackets. it's matching those.
@"\s*[\(\[\{]\s*[a]\s*[n]\s*[\}\]\)]\s*"
also, fwiw, pattern doesn't check ensure brackets same. get, e.g., [an}
or (an]
.
to this, you'd need like:
\(\s*a\s*n\s*\)|\{\s*a\s*n\s*\}|\[\s*a\s*n\s*\]
i'm sure there's prettier way, it's escaping me right now.
c# asp.net .net regex
No comments:
Post a Comment