www.webdeveloper.com
Results 1 to 4 of 4

Thread: Reg Exp for solving combo filter...

  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Reg Exp for solving combo filter...

    Hi People,

    I would like to have your help on it because I tried to solve it by myself so many times and I could not.

    I have a combo box that has to be filtered by an input text entry.

    The text in the combo is something like this:
    004-83299-001 (AUC) Stateline Auto Auction

    And I have a search by PDN (5h position to the 9th position = 83299 in this example), and by Dealer Name (from the 15th position to the end = (AUC) Stateline Auto Auction in this example).

    When searching by the PDN it has to look just on those 5 positions and in the text it can find any text that starts with what I typed.

    For example, if I type "line 299", it can not find the text, but if I type "832 State", it has to find it because of the PDN and part of the Dealer name text.

    I am creating one Regular Expression object for each word entered in the text input field and applying them to both blocks of each line of combo box.

    I used the following reg exp: (^|\s*) + text entered.
    The problem with this approach is that it is looking for the text in any part of the string but I can work only with the beginning of the words.

    Could anyone here please help me?

    Thanks!

    var vStringsToSearch = pattern.split(' ');
    var vRegExpPatterns = new Array();
    for (var i = 0; i < vStringsToSearch.length; i++)
    {
    vStringsToSearch[i] = '(^|\s*)' + vStringsToSearch[i].
    replace(/([\\\^\$*+[\]?{}.=!|)])/g,"\\$1") + '.*';

    try
    {
    // Initialize the regexp
    vRegExpPatterns[i] = new RegExp(String(vStringsToSearch[i]), this.ignoreCaseFlag);

    alert(vStringsToSearch[i]);
    }
    catch(e)
    {
    return;
    }

    }

    for (loop=0; loop < this.listObjCopy.length; loop++)
    {
    var found = true;
    option = this.listObjCopy[loop];

    for (loop2=0; loop2 < vRegExpPatterns.length; loop2++)
    {
    if (!vRegExpPatterns[loop2].test(option.text.substring(startFirstPos, endFirstPos)))
    {
    if ((startScndPos > 0) && (endScndPos > 0))
    {
    if (!vRegExpPatterns[loop2].test(option.text.substring(startScndPos, endScndPos)))
    {
    found = false;
    break;
    }
    }
    }
    }

    if (found)
    {
    this.listObj.options[index++] = new Option(option.text, option.value, false);
    }
    }

  2. #2
    Join Date
    Dec 2002
    Location
    Pleasanton, CA
    Posts
    2,132
    In order to solve the problem, you need to more clearly define it.

    004-83299-001 (AUC) Stateline Auto Auction

    You want to match any part of the PDN followed by any part of the dealer name???
    Should it match '29 (A' -or- '9 S' for example??

  3. #3
    Join Date
    Aug 2009
    Posts
    2
    In fact if the user type 299 it has not to find anything expect if the 299 is in the Dealer Name.

    It has to find the Dealer if I type "832 State" or "Auto 832". Something like this.

    The PDN has to be looked at the begining of the text while the Dealer Name has to be looked at the whole string but only in the beginning of the texts.

  4. #4
    Join Date
    Dec 2002
    Location
    Pleasanton, CA
    Posts
    2,132
    I still don't understand what is your criteria but maybe this will help to get you started.
    Code:
    var combo = '004-83299-001 (AUC) Stateline Auto Auction';
    var PDN = '832';
    var dealer = 'Auto';
    
    if (PDN && dealer) {
    	var reA = new RegExp('^.+?'+PDN+'.+?'+dealer+'.+$');
    	if (reA.test(combo)) { alert('found') } else { alert('not found'); }
    }
    else {
    	alert('invalid');
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles