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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -