Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:07:29+00:00 2026-06-15T17:07:29+00:00

There is an array var words =new Array( ‘apple’, ‘apa’, ‘found’, ‘stackoverflow’, ‘will’ );

  • 0

There is an array

var words =new Array(
            'apple',
            'apa',
            'found',
            'stackoverflow',
            'will'
   );

and a variable

var search = 'papa.com';

Now I want to set an expression like this

var Flag=false;
var regexp;
for(var i in words) 
{
    regexp = new RegExp('(^(.*\.))?' + words[i] + '\.([a-z]{2,3})(\.(\w+))?','i');
    if (regexp.test(search)) {Flag=true;}
}
alert (Flag);

The loop is supposed to get words array keys one by one, then set the regular expression and test the search variable against the built expression, if there where one or more match the Flag will come out with true.

But, id doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:07:30+00:00Added an answer on June 15, 2026 at 5:07 pm

    You need to escape your escape sequences when you build a regex from a string. This is because a \ in string literal notation also begins an escape sequence, and so the \ is removed.

    To include a literal \ character in a string built from literal syntax, you need \\.

    regexp = new RegExp('(^(.*\\.))?' + words[i] + '\\.([a-z]{2,3})(\\.(\\w+))?','i');
    

    Your regex was ending up with . instead of \., which would of course have very different meaning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the website I'm accessing, there is a javascript array (var arrayname) that has
Is there any other better way to fill up the array like : var
So there is this function Array.prototype.containsCaseInsensitive = function(obj) { var i = this.length; while
I am making a page in which there will be array of images. I
  var mymarkers= []; //array function createMarker(point,html,ref){ var marker = new GMarker(point); mymarkers[ref] =
Crockford writes in http://javascript.crockford.com/survey.html : There are two ways to make a new array:
on a website i want to do this: (simplified) myHandlers = new Array(); for(var
var filters_used = new Array(); $('#filter-text').keyup(function(k) { $('#error').html(''); if (k.keyCode == 13) { $('#add-filter').click();
There is an array of user states stored in the session. This works: <?php
Scenario: If there is an array of integers and I want to get array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.