Programming Windows D Examples are now Online!
bearophile
bearophileHUGS at lycos.com
Wed Jun 22 20:01:50 PDT 2011
Andrej Mitrovic:
> Write a D script that removes extra parens from strings like these:
> ("Acoustic Bass Drum"), ("Bass Drum 1"),
> ("Side Stick"), ("Acoustic Snare"),
> ("Hand Clap"), ("Electric Snare"),
> ("Low Floor Tom"), ("Closed High Hat"),
> ("High Floor Tom"), ("Pedal High Hat"),
>
> and replaces it with:
> "Acoustic Bass Drum", "Bass Drum 1",
> "Side Stick", "Acoustic Snare",
> "Hand Clap", "Electric Snare",
> "Low Floor Tom", "Closed High Hat",
> "High Floor Tom", "Pedal High Hat",
>
> I can't figure std.regex out. Every time I try to use the hit()
> property of a RegexMatch object I get back some weird internal error:
>
> core.exception.AssertError at D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\regex.d(1861):
> 4294967295 .. 4294967295 vs. 2
I suggest to minimize the case and submit a bug report for Phobos.
Regarding your problem, I have written this Python code, probably it's not too much hard to translate it to D:
import re
lines = """
> The parens are leftover from code like this:
> TEXT ("Acoustic Bass Drum"), TEXT ("Bass Drum 1"),
> TEXT ("Side Stick"), TEXT ("Acoustic Snare"),
> TEXT ("Hand Clap"), TEXT ("Electric Snare"),
> TEXT ("Low Floor Tom"), TEXT ("Closed High Hat"),
> TEXT ("High Floor Tom"), TEXT ("Pedal High Hat"),
""".splitlines()
patt = re.compile(r"""
TEXT \s* \(
\s*
(".*?")
\s*
\) """, re.VERBOSE)
def replacer(m):
return str(m.group(1))
for line in lines:
print patt.sub(replacer, line)
I have used redemo2.pyw
Bye,
bearophile
More information about the Digitalmars-d-announce
mailing list