Path: csiph.com!aioe.org!.POSTED.O5hsyUvK01te0L/SZurVSQ.user.gioia.aioe.org!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Because ramine plugging comp.programming with spam.... Date: Wed, 27 Nov 2019 18:31:28 -0500 Organization: Aioe.org NNTP Server Lines: 52 Message-ID: References: <64859ebd-4194-4b36-ae6b-80135a519db2@googlegroups.com> NNTP-Posting-Host: O5hsyUvK01te0L/SZurVSQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: csiph.com comp.lang.java.programmer:39196 On 11/27/2019 8:32 AM, chad altenburg wrote: > This is sort of Java related. > > This is about searching for a word in a Java using regex. > > I have the word "AlarmService". > > 1)searching for "alarm" produces "AlarmService" > > 2)searching for "alarmS" produces nothing > > 3)searching for "AlarmS" produces "AlarmService" > > The question is how come having a lowercase in "a" in 1 produces the entire word > while the lowercase "a" in 2 doesn't? Ie, I have to change it uppercase in order to get the correct result. Could you show some code? Because I cannot recreate the problem. import java.util.regex.Pattern; public class RegexMatch { public static void test(String needle, String haystack) { Pattern p = Pattern.compile(needle); System.out.printf("Standard match %s in %s : %b\n", needle, haystack, p.matcher(haystack).find()); Pattern pi = Pattern.compile(needle, Pattern.CASE_INSENSITIVE); System.out.printf("Case insensitive match %s in %s : %b\n", needle, haystack, pi.matcher(haystack).find()); } public static void main(String[] args) { test("alarm", "AlarmService"); test("alarmS", "AlarmService"); test("AlarmS", "AlarmService"); } } produces: Standard match alarm in AlarmService : false Case insensitive match alarm in AlarmService : true Standard match alarmS in AlarmService : false Case insensitive match alarmS in AlarmService : true Standard match AlarmS in AlarmService : true Case insensitive match AlarmS in AlarmService : true which matches my expectations. Arne