Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #15984
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Gene Wirchenko <genew@ocis.net> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: need regular expression to replace part of result based on a search pattern |
| Date | Thu, 12 Jul 2012 09:18:18 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 41 |
| Message-ID | <ptttv71mt6jf2mog2p2fr7816am6gpka7l@4ax.com> (permalink) |
| References | <6aefda61-b66a-4e8f-8634-ef6a95f79c4d@googlegroups.com> <VMednY1XR8zyf2PSnZ2dnUVZ8ridnZ2d@giganews.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | mx04.eternal-september.org; posting-host="c0a6a1dc41fc92eb7000e57afbd16211"; logging-data="32186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EsB6rgDp9OXnpXCVDhao2mkkzGl+cZZo=" |
| X-Newsreader | Forte Agent 4.2/32.1118 |
| Cancel-Lock | sha1:Xl0TkBttKmcoAooBMm08MPTeF3E= |
| Xref | csiph.com comp.lang.java.programmer:15984 |
Show key headers only | View raw
On Thu, 12 Jul 2012 09:42:55 -0500, Leif Roar Moldskred
<leifm@dimnakorr.com> wrote:
>Jimmy <jimmy_please@yahoo.com> wrote:
>> Have been having hard time to come up with the regular expression to replace the following..
>
>Then don't use a regular expression.
>
>There's a quote by Brian Kernighan that “Debugging is twice as hard as
>writing the code in the first place. Therefore, if you write the code
>as cleverly as possible, you are, by definition, not smart enough to
>debug it.”
A bit of exaggeration, but not much.
>In other words, if it's not quickly obvious how to write a regular
>expression that does what you want, use something else. Your
>maintenance programmers (often your six-month older self) will thank
>you.
If you really, really, really have to do it, know that you will
end up with Write-Only code so isolate as much as you can. Document
it, and hope that you never have to deal with it again. If you do,
you will appreciate the documentation.
>From the description you've given of the problem, I would think that
>your best bet is to parse your input as a CSV, do the required
>changes, and write it back into a CSV. Easier to write and easier to
>read than a dose of line noise.
And easier to modify. What if you later have to also modify
column 4 to always have 'N'? If your first reaction is negative, then
your code is too complex.
I write a lot of my code without worrying much about how fast or
elegant it is. Usually, it is quite fast enough, and it is
maintainable.
Sincerely,
Gene Wirchenko
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
need regular expression to replace part of result based on a search pattern Jimmy <jimmy_please@yahoo.com> - 2012-07-11 10:35 -0700
Re: need regular expression to replace part of result based on a search pattern Roedy Green <see_website@mindprod.com.invalid> - 2012-07-11 15:24 -0700
Re: need regular expression to replace part of result based on a search pattern Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2012-07-11 15:40 -0700
Re: need regular expression to replace part of result based on a search pattern Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-12 00:56 +0200
Re: need regular expression to replace part of result based on a search pattern Roedy Green <see_website@mindprod.com.invalid> - 2012-07-11 21:21 -0700
Re: need regular expression to replace part of result based on a search pattern Jimmy <jimmy_please@yahoo.com> - 2012-07-12 07:28 -0700
Re: need regular expression to replace part of result based on a search pattern Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-12 11:24 -0400
Re: need regular expression to replace part of result based on a search pattern Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-07-12 11:42 -0400
Re: need regular expression to replace part of result based on a search pattern Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 22:55 -0400
Re: need regular expression to replace part of result based on a search pattern Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-07-12 09:42 -0500
Re: need regular expression to replace part of result based on a search pattern Gene Wirchenko <genew@ocis.net> - 2012-07-12 09:18 -0700
Re: need regular expression to replace part of result based on a search pattern glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-07-12 18:34 +0000
Re: need regular expression to replace part of result based on a search pattern Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 22:53 -0400
Re: need regular expression to replace part of result based on a search pattern Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 22:48 -0400
Re: need regular expression to replace part of result based on a search pattern Arne Vajhøj <arne@vajhoej.dk> - 2012-07-25 17:37 -0400
csiph-web