简体   繁体   English

正则表达式排除特定的子字符串模式

[英]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 . 215可以是任何数字。 Its can be a normal decimal or hexadecimal . 它可以是普通的十进制或十六进制。 if it is a hexadecimal number then it starts with 'x' after &# . 如果它是十六进制数,则它在&#之后以'x'开头。

How can I achive this? 我该如何实现?

Think you mean this, 以为你是这个意思,

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

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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