[plug] Save a soul from scripting insanity [conclusion?]

ryan at is.as.geeky.as ryan at is.as.geeky.as
Thu Aug 15 11:12:41 WST 2002


----- Original Message -----
From: "Anthony J. Breeds-Taurima" <tony at cantech.net.au>

> Ummm Why do you need the 'm' prefix?  AFAIK
> m{Translator\.translate\("((?:\\["\\]|[^"])*)"[^\)]*\)}g;
> == /Translator\.translate\("((?:\\["\\]|[^"])*)"[^\)]*\)/g;
>
> albeit slightly easier to read
>

Correct, I never said I knew what I was doing, I just know how to make regex
patterns, not how use them :)   Thanks.   It was a slight hang over from all
the simplification steps I performed on my first awful try.

> Does it handle?
> ---
> System.out.println(Translator.translate(
> "String 1") +ojb.meth() +Translator.translate("String 2a"
> +"\"String 2b;\"",27, 12),
> Translator.translate("(String 3)"));
> ---
>
> I tried very hard to come up with one (or even two regex's) that would
work
> and failed.  If you've managed to do it then I need to take my hat off ;P.
>

Not a common occurance I would have though (the first line break), but how
about trying this:

  @found = $data =~
/Translator\.translate\((?:[\s\n^"])*"((?:\\["\\]|[^"])*)"[^\)]*\)/g;

Produces:
==========
String 1
String 2a\"String 2b;\"
(String 3)
==========

Works fine for me on all past examples plus your new hairy one, of course
there will be more exceptions - this is not a java parser after all.  It
does however seem to answer the problem that Russell had, so it is somewhat
useful  to someone :)

Ryan




More information about the plug mailing list