Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts

    Regular Expression for new line

    Hello,
    I am trying to split:

    Code:
    |Version|Date|Author|Changes
    1.0|5/5/2008|David Kisley|Initial Issue
    1.0|5/5/2008|David Kisley|Initial Issue
    1.0|5/5/2008|David Kisley|Initial Issue
    1.0|5/5/2008|David Kisley|Initial Issue
    into separate lines split on the new line 'character' at the end of each line and put the lines into an array for further processing. Does anybody have any idea how to split these in the new line 'character'? Thank you.

    Don

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by dragon6158 View Post
    into separate lines split on the new line 'character' at the end of each line and put the lines into an array for further processing. Does anybody have any idea how to split these in the new line 'character'?
    Try str.split(/\n\r?/);

  • #3
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Unfortunately it didn't work. I can split the lines if I wrap them in <pre> tags but if I use <table> tags, it won't split the lines. I am trying to dynamically build a table using the data that looks like the example and if I could do the split in the <table> tag it would be the best way. I can build the rows but not the table yet. Thanks.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,461
    Thanks
    11
    Thanked 600 Times in 580 Posts
    post the code to build rows, and we can finish it.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,461
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Quote Originally Posted by Arty Effem View Post
    Try str.split(/\n\r?/);
    i think that your regExp should actually be /\r?\n/g
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Does this help?

    Code:
    <script type = "text/javascript">
    
    var x = "1.0|5/5/2008|David Kisley|Initial Issue 1.0|5/5/2008|David Kisley|Initial Issue 1.0|5/5/2008|David Kisley|Initial Issue 1.0|5/5/2008|David Kisley|Initial Issue"
    
    x = x.replace(/Issue /gi, "Issue\n");
    alert (x);
    x = x.split("\n");
    alert (x[0]);
    alert (x[1]);
    
    </script>
    EDIT: Perhaps not, unless the final word in each entry is "issue". I am not very clear why all four entries are the same, or where they are coming from.


    When trouble arises and things look bad, there is always one individual who perceives a solution and is willing to take command. Very often, that individual is crazy.
    Last edited by Philip M; 06-12-2008 at 09:50 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •