Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: regex replaceAll? Date: Thu, 1 Mar 2018 19:49:26 -0500 Organization: Aioe.org NNTP Server Lines: 37 Message-ID: References: <4a800440-39fe-4684-8369-e6a4e6b9d79f@googlegroups.com> <44c665e1-e965-4e9b-8aa0-72aa20607e63@googlegroups.com> <8c677118-8115-409d-8d3b-396e54b063ae@googlegroups.com> NNTP-Posting-Host: PBuS014lhzVyHjLbXmo/ZQ.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:52.0) Gecko/20100101 Thunderbird/52.6.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.8.3 Xref: csiph.com comp.lang.java.programmer:38103 On 3/1/2018 7:43 PM, Kiwi User wrote: > On Thu, 01 Mar 2018 22:31:08 +0000, Andreas Leitgeb wrote: >> It's pretty normal that some attempt at writing an RE to solve a problem >> doesn't work at first time. >> >> Then, there's essentially two strategies: >> >> 1) randomly shuffle around the funny symbols and see if that >> works then. If the reshuffled variant doesn't work, either, >> go back to original and defend it: "tried other way, but didn't >> work any better." >> >> 2) analyze what the RE is really doing, and refine it to do >> what you want it to do. >> >> take your choice... >> > Another way to test regexes may help: use an online regex test tool like > this one: > > http://www.regexplanet.com/advanced/java/index.html > > It helps because it: > - tests an expression without you writing anything except the regex > - lets you submit a set of test strings and run repeated tests against > them > - has check boxes for making caseless comparisons, etc. Yes. But if the regex is so complicated/unreadable that it is not obvious whether it works or not, then I would question whether regex is the right choice. Arne