简体   繁体   English

如何忽略C#正则表达式中的空格

[英]how to ignore spaces in c# regex

what is the c# equivalent of /x in perl for regex, so the /x at the end would ignore all the whitespaces newlines and whatnot in your regex expression. regex在perl中与/ x的c#等效项是什么,因此/ x末尾将忽略所有空格换行符和regex表达式中的内容。 Otherwise, my expression would be a giant one liner instead of a little block. 否则,我的表情将是一个巨大的内胆而不是一个小方块。 Any other way around it? 还有其他解决方法吗?

There's an option you can specify when constructing the Regex : 构造Regex时可以指定一个选项:

new Regex("...expression here...", RegexOptions.IgnorePatternWhitespace)

Since RegexOptions is a flag type, you can binary-OR this flag with any existing flags you may specify. 由于RegexOptions是标志类型,因此您可以将此标志与您可以指定的任何现有标志进行二进制或运算。

The /x inline character is supported. 支持/ x内联字符。 See here . 看这里

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

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