Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
570 views
in Technique[技术] by (71.8m points)

c# - Case insensitive Regex without using RegexOptions enumeration

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:

  • Taylor
  • taylor
  • taYloR
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

MSDN Documentation

(?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, case insensitive
  • s, single line mode
  • m, multi line mode
  • x, free spacing mode

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...