Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Bug in Mathematica: regular expression applied to very
Replies: 1   Last Post: Feb 14, 2010 8:17 AM

 yehuda ben-shimol Posts: 302 Registered: 2/11/05
Re: Bug in Mathematica: regular expression applied to very
Posted: Feb 14, 2010 8:17 AM

You can use the MAthematica string manipulation functions.
Let me lengthen the string in an obvious way, by duplicating it 1000 times.
s = "This is the first line.
MAGIC_STRING
Everything after this line should get removed.
12345678901234567890123456789012345678901234567890123456789012345678\
901234567890
12345678901234567890123456789012345678901234567890123456789012345678\
901234567890
12345678901234567890123456789012345678901234567890123456789012345678\
901234567890
12345678901234567890123456789012345678901234567890123456789012345678\
901234567890
12345678901234567890123456789012345678901234567890123456789012345678\
901234567890
...";

s = Nest[StringJoin[s, #] &, s, 1000];

StringLength[s]

492492

StringDrop[
StringReplace[
s, (p : Shortest[___ ~~ "\n" ~~ ___ ~~ "\n" ~~ ___ ~~
"\n"]) ~~ ___ :> p], -1]

so, processing only part of the string (using Shortest) gives the result in
a fraction of a second

yehuda

On Sun, Feb 14, 2010 at 12:59 PM, dreeves <dreeves@gmail.com> wrote:

> I believe I found a bug in Mathematica's regular expression engine:
>
> http://stackoverflow.com/questions/2257884/bug-in-mathematica-reg
>
> I've submitted a bug report to support@wolfram but also wondering if
> you all have thoughts on workarounds.
>
> Thanks!
>
> PS: Here's an rss feed of questions tagged mathematica on
> stackoverflow:
> http://stackoverflow.com/feeds/tag?tagnames=mathematica
>
>