c# - New rule to existing regex allowing single quotes -
i asked another question here, still having problems it.
i have expression follows rules:
- the character ' must first , last character
- there can zero-or-more spaces inside ''
- there can zero-or-more % inside ''
there can zero-or-more words (letters , numbers) inside '' expression:
(?i)^(?<q>['])[%\p{zs}\p{l}\p{n}|()]*\k<q>$
now, there must rule:
- there can zero-or-more words between '' pairs.
example:
'content1' text should pass 'content2'
update:
the trick here following should pass:
' content ' text ' > pass ' ' content ' > pass
what like? if know books regular expressions, useful me.
you can add alternative list using |
operator:
^(?<q>')(?:'[^']*'|[%\p{zs}\p{l}\p{n}|()])*\k<q>$
i removed []
around '
, placed *
quantifier alternative list. also, (?i)
redundant since there no literal letters in regex.
here regex demo
mind 'content1' won't pass 'content2'
won't pass, guess expected behavior.
update:
if want allow '
in between '...'
, can add character class:
^(?<q>')['%\p{zs}\p{l}\p{n}|()]*\k<q>$
see another demo (\r?
added demo purposes in multiline mode there)
Comments
Post a Comment