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
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    returning part of content which matches pattern

    heres my code so far for my homework

    Code:
     mypages=["www.google.com|google is a very popular search engine.",
    "www.bing.com|bing is another search engine.",
    "www.ask.com|ask is yet another search engine."
    ];
    
    
    
    //function join(mypages,pattern)
    {if(mypages[0].toLowerCase().match(pattern.toLowerCase()))//.match String Object is used to match page with the pattern 
    return "www.google.com";
    else if(mypages[1].toLowerCase().match(pattern.toLowerCase()))
    return "www.bing.com" ;
    else if(mypages[3].toLowerCase().match(pattern.toLowerCase()))
    return "www.ask.com";
    else 
    return "";} //returns an empty string because no match is found

    an issue i am having is I have to make it so the search ignores the website when searching eg.
    alert(join(mypages,"www.bing.co.uk")
    returns ""

    it has to ignore the array including the |

    any tips?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    And the point of that is?

    The only way would be to obfuscate the array with encryption of some sort.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    And the point of that is?

    The only way would be to obfuscate the array with encryption of some sort.
    Could there be an alternative method eg using a loop be more easier?

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    I am unclear of the requirement...

    Do you want to do something when a match is found OR do you want to avoid doing something???


  •  

    Posting Permissions

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