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 4 of 4
Like Tree2Likes
  • 1 Post By xelawho
  • 1 Post By rnd me

Thread: Regular Expressions

  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    78
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question Regular Expressions

    Suppose I have 3 strings
    1)Aborted CVRT
    2)Aborted Dif
    3)CVRT

    • Now If I type in a search box "CVRT" it should not display the string Aborted CVRT it should only display CVRT

      records.
    • If I type Aborted CVRT it should search Aborted CVRT only,
    • If I type CVRT then it should search only CVRT records
    • and If I type Aborted Dif It should search only Aborted DIF



    How can this achieve using regular expressions


    Thanks in advance

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    I don't know what the records are, but maybe this could help you get started. No regex, but it didn't seem necessary...

    Code:
      <body>  
    <input id="inp"/>
    <div id="disp"></div>
    <script type="text/javascript">
    document.getElementById("inp").onkeyup=function () {
    document.getElementById("disp").innerHTML="";
    var theinp=this.value.toLowerCase();
    var strings={
    "aborted cvrt":"something about Aborted CVRT",
    "aborted dif":"sometihng about Aborted Dif",
    "cvrt":"something about CVRT"
    }
    if(theinp in strings){
    document.getElementById("disp").innerHTML=strings[theinp];
    }
    
    };
    
    </script>
    </body>
    prajwala likes this.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,461
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Code:
    var alls=["Aborted CVRT", "Aborted Dif", "CVRT"];
    
    var matcher="Aborted C";
    
    var hits=alls.filter(/./.test, RegExp("^" + matcher))
    alert(hits)
    prajwala likes this.
    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%

  • #4
    New Coder
    Join Date
    Feb 2007
    Posts
    78
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Can you pls explain me about alls.filter(/./.test, RegExp("^" + matcher))?


  •  

    Posting Permissions

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