正则表达式不区分大小写

Regex is used given text according to different and flexible patterns. It provides a lot of different patterns which can match given text or line. The default behavior of the regex is case sensitive which means upper and lowercase letters are interpreted as different. We can match regex case insensitive or ignore case sensitivity.

正则表达式根据不同灵活的模式使用给定的文本。 它提供了许多可以匹配给定文本或行的不同模式。 正则表达式的默认行为区分大小写,这意味着大写和小写字母被解释为不同。 我们可以匹配不区分大小写的正则表达式,也可以忽略大小写。

不区分大小写作为Grep选项 (Case Insensitive As Grep Option)

grep is very popular tool which is used to filter given text with different patterns. grep command also supports Regex or regular expressions and run regex as case sensitive by default. We can disable case-sensitive match with the -i option.

grep是非常流行的工具,用于过滤具有不同模式的给定文本。 grep命令还支持正则表达式或正则表达式,并且默认情况下以区分大小写的方式运行正则表达式。 我们可以使用-i选项禁用区分大小写的匹配。

$ grep -i "poftut" hostnames
Case Insensitive As Grep Option
不区分大小写作为Grep选项

不区分大小写作为正则表达式选项(Case Insensitive As Regular Expression Option)

Regex language also provides an opportunity to make given regex pattern to be case insensitive. We can use (?i) which means the given regex will be case insensitive.

正则表达式语言还提供了使给定的正则表达式模式不区分大小写的机会。 我们可以使用(?i) ,这意味着给定的正则表达式将不区分大小写。

poftut(?i)

Java (Java)

In Java programming language we can use Pattern class which can use Regex and provide CASE_INSENSTIVE as an option. In this example, we will create a Regex pattern named patter which will be case insensitive.

在Java编程语言中,我们可以使用Pattern类,该类可以使用Regex并提供CASE_INSENSTIVE作为选项。 在此示例中,我们将创建一个名为patter的正则表达式模式,该模式不区分大小写。

Pattern pattern = Patternpile("poftut", Pattern.CASE_INSENSITIVE);

不区分大小写作为正则表达式 (Case Insensitive As Regular Expression)

Regular expressions also support different patterns to specify numbers letters, upper case letters, lower case letters etc. We can combine upper and lower case letters. [a-z] means lowercase letters and [A-Z] means upper case letters. We can create case insensitivity like below from both upper and lower case letters.

正则表达式还支持不同的模式来指定数字字母,大写字母,小写字母等。我们可以将大写和小写字母组合在一起。 [az]表示小写字母, [AZ]表示大写字母。 我们可以通过大小写字母在下面创建不区分大小写的代码。

[a-zA-Z]
LEARN MORE  What Is Wildcard Character(s)? 了解更多什么是通配符?

翻译自: https://www.poftut/how-to-create-case-insensitive-regex/

正则表达式不区分大小写

更多推荐

正则表达式不区分大小写_如何创建不区分大小写的正则表达式?