Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: multi-line Strings Date: Sun, 16 Dec 2012 12:19:53 -0700 Organization: bilaterally symmetric Lines: 51 Message-ID: References: <7f36342c-2331-4484-874b-4a0f8953f160@googlegroups.com> <50c61150$0$293$14726298@news.sunsite.dk> <50c6413a$0$293$14726298@news.sunsite.dk> <50c6598d$0$290$14726298@news.sunsite.dk> <50c69625$0$293$14726298@news.sunsite.dk> <50cbeec3$0$291$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="75975abe3fe3503ca7350803ab98e478"; logging-data="13442"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Z1T7rBETwbvut4AjNG8Zy" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:SHAM9fOTCjKhWDnYGciEDK0iZFw= sha1:I0+vQUPZgtbZfKbqVv/OLLhRZWI= Xref: csiph.com comp.lang.java.programmer:20384 "Chris Uppal" writes: > Arne Vajhøj wrote: > >> The regex syntax itself is not exactly a good example of readability. > > This, I think, is the point. We don't need a special String syntax to fix the > problem with regexps -- we'd be much better off with a fixed regexp syntax. > Something OO. And (since this is Java) I don't think that we need be afraid of > something verbose. > > Off-the-top-of-my-head (all classes and method are imaginary): > > Regexp alpha = Regexp.fromList(java.lang.text.portable.Alphas); > alpha = alpha.or('_'); > Regexp num = Regexp.fromList(java.lang.text.portable.Digits); > Regexp alphanum = alpha.or(num); > Regexp identifier = alpha.followedBy(alphanum.repeated()); > > Naturally, I'd prefer something a /bit/ less verbose, but Java won't support > that. But even with the verbosity, I think my version is /far/ better. It > puts the composition of regexps into the programmer's hands which means that it > can be approached like any other complex programming task. Quoting/escaping > problems go away. Grouping (bracketing) problems go away (and become > decoupled from the backreference concept. Comments become trivially easy to > add. Various kinds of abstraction and reuse are possible. > > -- chris > > P.S. Mind you: my /real/ opinion is that regular expressions have no place in > production code except in the construction of scanners (for which a more > directly-applicable implementation than standalone regexps is helpful). > Regexps are for users to enter, or go into configuration data. At least the > suggestion above has the advantage -- from my point of view -- that regexps no > longer look like "quick and easy" fixes to problems, and maybe the programmer > would think more about whether they /actually/ solve [all of] the problem at > hand. > > P.P.S UK post codes... For me the native regexp syntax usually becomes unmanageable at about the same time that I'm ready to decide that regexps aren't the best approach anyway. But there are some Java libraries for building complex regexps. A quick Google search turns up this one http://reggert.github.com/reb4j/ I thought I remembered another one, but I can't find it now. -- Jim Janney