Regex to find all matches for display in a table

Comments

2 comments

  • Rainer Grabowski

    Hi Rich,

    cause your source string (dupltable) is structered very well you don't need regex, match, while. A simple nested for-loop does the job.

    var dupltable = "U1533|5122330121,5127624861|bababngaustin@gmail.com|ConradBering U1534|3655483644|DTMNODDTES@GMAIL.COM|JackTodd U1535|5124440936|J.GAMMOWAY09@GMAIL.COM|JohnGammoway U1536|5128045529|DTMNODDTES@GMAIL.COM|KevinBarr "
    var dupltable = dupltable.trim().replace(/ /g," ").split(" ");

    var searchFor = "5127624861";

    var matches = [];
    for(var i = 0; i < dupltable.length; i++){
    var subSplit = dupltable[i].split("|");
    for(var j = 0; j < subSplit.length; j++){
    if(searchFor == subSplit[j] || subSplit[j].indexOf(searchFor +",") > -1 || subSplit[j].indexOf("," + searchFor) > -1){
    matches.push(dupltable[i])
    }}};

    "found " + matches.length + " matches: \n" + matches.join("\n")

    Result is: 
    found 1 matches:
    U1533|5122330121,5127624861|bababngaustin@gmail.com|ConradBering

    Search for DTMNODDTES@GMAIL.COM and you'll see it finds 2 dups (cause I've added that email to another row).

    Several month ago I've created a duplicate check system based on calculation fields for a contact app with > 15,000 items. Works great.

    It returns the result as URLs (links to the found dups) and tells if the phone is a duplicate or the email or both.

    On top it creates items in a Duplicate-Handling app where a user can merge the dups. Have implemented that solution now for multiple clients.  

    Rainer 

     

    0
    Comment actions Permalink
  • Rich Siegmund

    I should add that I've seen comments from RG and others about pitfalls when searching on fields that are/are not text fields, but for my example I've hardcoded the search string. Have also seen a need to use JSON.stringify, but that didn't help.

     

    -1
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk