不区分大小写的正则表达式,而不使用RegexOptions枚举 [英] Case insensitive Regex without using RegexOptions enumeration

查看:120
本文介绍了不区分大小写的正则表达式,而不使用RegexOptions枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时不设置RegexOptions.IgnoreCase标志可以使用Regex类做一个区分大小写的比赛在C#?

Is it possible to do a case insensitive match in C# using the Regex class without setting the RegexOptions.IgnoreCase flag?

我想能够做到是正则表达式中本身定义我是否要在不区分大小写的方式来完成的匹配操作。

What I would like to be able to do is within the regex itself define whether or not I want the match operation to be done in a case insensitive manner.

我想这正则表达式,泰勒,以匹配以下值:

I would like this regex, taylor, to match on the following values:


  • 泰勒

  • 泰勒

  • 泰勒

推荐答案

MSDN文档

(我)泰勒匹配的是我,而不必设置RegexOptions.IgnoreCase标志指定的输入。

(?i)taylor matches all of the inputs I specified without having to set the RegexOptions.IgnoreCase flag.

要强制区分大小写我可以做( - 我?)泰勒

To force case sensitivity I can do (?-i)taylor.

它看起来像其他选项包括:

It looks like other options include:


  • I ,不区分大小写

  • 取值,单线模式

  • M ,多行模式

  • X ,无间隔模式

  • i, case insensitive
  • s, single line mode
  • m, multi line mode
  • x, free spacing mode

这篇关于不区分大小写的正则表达式,而不使用RegexOptions枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆