RegEx: Two of (Newline + Whitespace) + alphanumeric. Can't get it!

Discussion in 'JavaScript' started by johnywhy, Dec 3, 2022.

  1. #1
    I thought one of these would work, but none of them work. Starting with my favorite:
    
    
    // 2 or more ( newline + 0 or more (spaces or tabs) )
    //     + any alphanumeric
    const gRecordDelim = /(\n[ \t]*){2,}(?=\w)/g;
    
    // const gRecordDelim = /(\n[ \t]*\n)/g;
    // const gRecordDelim = /(\n[ \t]*){2,}(?=[A-Za-z0-9])/g;
    // const gRecordDelim = /(\n[ \t]*){2,}\n/g;
    // const gRecordDelim = /\n{2,}/g;
    // const gRecordDelim = /([ \t]*\n[ \t]*){2,}/g;
    
    Code (markup):
    It's a split pattern in javascript:
    
    
    const recs = text.split(gRecordDelim);
    recs.forEach((rec) => console.log("RECORD: " + rec))
    
    Code (markup):
    Here's my data.
    
    
    const text = `
            Orblie Rapitulnik
            orbliek.jpg
            orbliek.com
            There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable.
        
            Qang Le Toenthal
            Qang.jpg
            Qangle.io
            Contrary to popular belief, Lorem Ipsum is not simply random text.`
    
    Code (markup):
    I'm getting the split at "Qang" as expected, but also splitting at the empty line, which i don't want.
    [​IMG]

    also posted to
    https://forum.webdeveloper.com/d/402130-regex-two-of-newline-whitespace-alphanumeric-cant-get-it
    https://www.sitepoint.com/community/t/regex-two-of-newline-whitespace-alphanumeric-cant-get-it/402561
     
    Last edited: Dec 3, 2022
    johnywhy, Dec 3, 2022 IP