Take the \s out of brackets.  I suspect that's your problem.  Also,
you're replacing with a dash, not a blank.

Or maybe I'm just tired.

--Ben

DURETTE, STEVEN J (AIT) wrote:

> Hi all,
>
> I have a little problem with some _javascript_ and a regex that I can't seem
> to figure out.
>
> I have the following code:
>
> <script language="_javascript_">
> <!--
>     function dispTest(){
>         var UpdprojStart = "     "; //five spaces.
>         UpdprojStart = UpdprojStart.replace("[\s]*", "-");
>         alert("|" + UpdprojStart + "|");
>
>         UpdprojStart = " 1 2 3 4 5"; //a space  before each number.
>         UpdprojStart = UpdprojStart.replace("[\s]*", "-");
>         alert("|" + UpdprojStart + "|");
>     }
> //-->
> </script>
>
> When I run it I get:
> first alert box: |     | (pipe, 5 spaces pipe)
> second alert box: | 1 2 3 4 5| (pipe, space, 1, space, 2, space, 3, space,
> 4, space 5, pipe)
>
> But I should have gotten:
> first alert box: || (pipe, pipe)
> second alert box: |12345| (pipe, 12345, pipe)
>
> I got the regex from the visual regex editor on the house of fusion.  What
> am I doing wrong that this won't work?
>
> Steve
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to