c# - Regular expression - Avoiding characters -
while using regex in c#, i'm facing following problem :
consider simple string : ~0~this simple text~pop~niz~0~0~
i pick strings between 2 '~', contains more 3 chars except of course '~'. in example, :
this simple text
i make : ([\w]|[\d]|.|\,.................){4-500}
i end long regex, impossible debug , not readable...
instead, prefer create regex "give me characters, except '~' contained between '~' , '~' ".
i can't find way use [^] !
how can ?
thanks in advance !
answer : i've done : ~[^~]{3,}~
it takes '~', contained between 2 '~' , more 3 chars long.
thanks answers !
if don't mind possible batch start , end, should easy as:
[^~]{3,}
or, can split , take long ones:
var tokens = str.split('~').where(s => s.length >= 3);
if want limit characters specific set, can use lookahead , behind make sure. not consume tilde signs, 2 matches ~123~abc~
(again, can use [^~]
if move comfortable it):
(?<=~)[\w\d\s]{3,}(?=~)
Comments
Post a Comment