简体   繁体   中英

Regex to exclude a particular substring pattern

My current regex code is as beow .

var caption = Regex.Replace(fileImage.Caption, @"[^\w\s\(\)\.@-]", "",RegexOptions.None);

Here I replace special characters with empty character excluding certain special characters
Now I have a strange situation where I along with above match i need to exculde a substring of type × where 215 can any number . Its can be a normal decimal or hexadecimal . if it is a hexadecimal number then it starts with 'x' after &# .

How can I achive this?

Think you mean this,

var caption = Regex.Replace(fileImage.Caption, @"(&#x?[a-f\d]+;)|[^\w\s\(\)\.@-]", "$1");

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM