How to split on a backslash '\' ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • oprah.chopra@gmail.com

    How to split on a backslash '\' ?

    The following code does not seem to work, I have tried all
    combinations of \\, \, \\\ etc. Unfortunately I can not change str .

    <script type="text/javascript">

    var str = 'Hello \ World';
    var pattern = /\\/;
    result = str.split( pattern );

    alert(result[0]);

    </script>
  • Lee

    #2
    Re: How to split on a backslash '\' ?

    oprah.chopra@gm ail.com said:
    >
    >The following code does not seem to work, I have tried all
    >combinations of \\, \, \\\ etc. Unfortunately I can not change str .
    >
    ><script type="text/javascript">
    >
    >var str = 'Hello \ World';
    >var pattern = /\\/;
    >result = str.split( pattern );
    >
    >alert(result[0]);
    >
    ></script>
    alert the value of str.
    You'll be surprised.


    --

    Comment

    • SAM

      #3
      Re: How to split on a backslash '\' ?

      oprah.chopra@gm ail.com a écrit :
      The following code does not seem to work, I have tried all
      combinations of \\, \, \\\ etc. Unfortunately I can not change str .
      >
      <script type="text/javascript">
      >
      var str = 'Hello \ World';
      var pattern = /\\/;
      the right patern would have to be :

      var pattern = /\ /;

      because :

      var str = 'Hello \ World';
      ^^
      result = str.split( pattern );
      or :

      result = str.split( '\ ' );

      alert(result[0]);
      >
      </script>

      Comment

      Working...