RegEx是否不区分大小写

RegEx是否不区分大小写

本文介绍了Java RegEx是否不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,当执行replaceAll寻找正则表达式模式时:

In Java, when doing a replaceAll to look for a regex pattern like:

replaceAll("\\?i\\b(\\w+)\\b(\\s+\\1)+\\b", "$1");

(删除重复的连续不区分大小写的单词,例如测试测试),我不知道在哪里我把?我。我读到它应该在开始时,但是如果我把它取出然后我会捕获重复的连续单词(例如测试测试),但不是不区分大小写的单词(例如测试测试)。所以我想我可以在开头添加?i但似乎没有完成工作。有什么想法吗?谢谢!

(to remove duplicate consecutive case-insensitive words, e.g. Test test), I'm not sure where I put the ?i. I read that it is supposed to be at the beginning, but if I take it out then i catch duplicate consecutive words (e.g. test test), but not case-insensitive words (e.g. Test test). So I thought I could add the ?i in the beginning but that does not seem to get the job done. Any thoughts? Thanks!

推荐答案

告诉我你是否想在开头加入它,这是正确的语法:

RegexBuddy is telling me if you want to include it at the beginning, this is the correct syntax:

"(?i)\\b(\\w+)\\b(\\s+\\1)+\\b"

这篇关于Java RegEx是否不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:04