c# - How to use Latin Extended Char in Regex -


i have list of character contains both normal special character latin extended character. want use special character regex.

list of spcl char:

var listadvspclchar = file.readlines(_spclcharfilepath, encoding.default);  stringbuilder sb = new stringbuilder(); foreach (string s in listadvspclchar) {    sb.append(s); } sb.tostring(); 

output :

,.()-"*/#ÃŽ‚¦:'‚°?_+~& ¢¬³¹¼;\=%Æ’º¯…™£$‹“]¾Â`^¡Âµ[ž±<}¨!>¸¥Âœ²©·Â«®Ë„§¤¿Â­¶´†»{| 

i want use above spcl char below

regex.ismatch(textstring, @"[^" + sb + "]"; 

i getting error parsing

"[,.()-"*/#ÃŽ‚¦:'‚°?_+~& ¢¬³¹¼ ;\=%Æ’º¯…™£$‹“]¾ `^¡ µ[ž±<}¨!>¸¥ œ²©· «®Ë„§¤¿ ­¶´†»{|]"  - [x-y] range in reverse order. 

and if adding \ each char getting error parsing

"[,\.\(\)\-\"\*\/\#\Ã\Æ’\Ã…\½\‚\Â\¦\:\'\â\€\Å¡\°\?\_\+\~\&\ \¢\¬\³\¹\¼\ \;\\\=\%\Æ\’\º\¯\…\â„¢\£\$\‹\“\]\¾\ \`\^\¡\ \µ\[\ž\±\<\}\¨\!\>\¸\Â¥\ \Å“\²\©\·\ \«\®\Ë\„\§\¤\¿\ \­\¶\´\†\»\{\|\]"  - unrecognized escape sequence \Ã. 

i have string line below:

00000001,0020,0000000000Ø00027006,paper tape 19 28°,759,1648.000 ,1648.000 ,,06092014,12319999,000100022404,halb,18.51 ,100 ,fs,pt-s12ds120-28,00166789,01,00000015,,00166789,m,01  00000001,0050,000000000000027006,paper tape 19 28°,759,2280.000 ,2280.000 ,,08262015,12319999,000100023811,halb,18.51 ,100 ,fs,s75p306p-3m,00166882,01,00000021,,00166882,m,010 

one of above line contains Ø not available in regex list unable find line error line.

the question can use above spcl char in regex

you need escape few char, see metacharacters inside character classes. can use code:

var listadvspclchar = file.readlines("your path", encoding.default); list<string> toescape = new list<string>() {     @"-",      @"\",     @"]", }; string escape = @"\"; stringbuilder sb = new stringbuilder(); foreach (string s in listadvspclchar) {     if (toescape.contains(s))     {         sb.append(escape);     }     sb.append(s); }  // , use it: regex.ismatch("textstring", string.format("[^{0}]", sb)); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -