Last active
July 3, 2018 10:33
-
-
Save yoshiki-0428/8f05d9fd14e04982d6716ff197774535 to your computer and use it in GitHub Desktop.
検索のキーワードを大小文字関係なくかつ検索元のワードを変更せずにマークアップする方法 ref: https://qiita.com/yoshiki-0428/items/b8221d0fa478b3efc9f7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String keyword = "java"; | |
String data = "Java java javaJava"; | |
// (?i)で大文字小文字区別しない | |
// ヒットした文字を()でグループ化 | |
data = data.replaceAll("((?i)" + Pattern.quote(keyword) + ")", "<mark>$1</mark>"); | |
// <mark>Java</mark> <mark>java</mark> <mark>java</mark><mark>Java</mark> | |
System.out.println(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pattern p = Pattern.compile(keyword, Pattern.CASE_INSENSITIVE).matcher(data); | |
while(p.find()) { | |
int start = p.start(); | |
int end = p.end(); | |
~発見した位置情報から計算してゴリゴリタグを埋めていく~ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment