简体   繁体   中英

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. 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 :

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.

The /x inline character is supported. See here .

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