RobB wrote:[color=blue]
> aliensite wrote:[color=green]
> > Lasse Reichstein Nielsen wrote:[color=darkred]
> > > "aliensite" <aliensite@excite.com> writes:
> > >
> > > > My code is too greedy, how can it be fixed?
> > > >
> > > > Here is my code:
> > > >
> > > > Desired output - First:,Second:,Third:
> > >
> > > So, in words, you want the parts between a ">" and the following[/color][/color]
> ":".[color=green][color=darkred]
> > >
> > > > <script type="text/javascript">
> > >
> > > var regEx = />([^:]*:)/g;
> > > var html = "<br>First:ratio<br />Second: 2:3<br>Third: size";
> > > var output = [];
> > > while (match = regEx.exec(html)) {
> > > output.push(match[1]);
> > > }
> > > document.write(output);
> > >
> > > Good luck
> > > /L
> > > --
> > > Lasse Reichstein Nielsen -
lrn@hotpop.com
> > > DHTML Death Colors:[/color]
> > <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>[color=darkred]
> > > 'Faith without judgement merely degrades the spirit divine.'[/color]
> >
> > Thanks, I tried several expressions, but it seems only a loop[/color][/color]
works.[color=blue][color=green]
> > Dave[/color]
>
> Possible alternative:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
> <html>
> <head>
> </head>
> <body>
> <pre>
> Input -
> &lt;br&gt;First:ratio&lt;br /&gt;Second:
> 2:3&lt;br&gt;Third: size
>
> Desired output -
> First:,Second:,Third:
>
> Actual output -
> <script type="text/javascript">
> var re = /<[^>]+>([^:]*):[^<]*/g;
> var html = '<br>First:ratio<br />Second: 2:3<br>Third: size';
> var output = html.replace(re, '$1:,').replace(/,$/, '');
> document.writeln(output);
> </script>
> </pre>
> </body>
> </html>[/color]
Nice :)