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 637601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:38:29+00:00 2026-05-13T20:38:29+00:00

text = ‘#container a.filter(.top).filter(.bottom).filter(.middle)’; regex = /(.*?)\.filter\((.*?)\)/; matches = text.match(regex); log(matches); // matches[1] is

  • 0
text = '#container a.filter(.top).filter(.bottom).filter(.middle)';

regex = /(.*?)\.filter\((.*?)\)/;

matches = text.match(regex);

log(matches);
// matches[1] is '#container a'
//matchss[2] is '.top'

I expect to capture

matches[1] is '#container a'
matches[2] is '.top'
matches[3] is '.bottom'
matches[4] is '.middle'

One solution would be to split the string into #container a and rest. Then take rest and execute recursive exec to get item inside ().

Update: I am posting a solution that does work. However I am looking for a better solution. Don’t really like the idea of splitting the string and then processing
Here is a solution that works.

matches = [];

var text = '#container a.filter(.top).filter(.bottom).filter(.middle)';
var regex = /(.*?)\.filter\((.*?)\)/;
var match = regex.exec(text);
firstPart = text.substring(match.index,match[1].length);
rest = text.substring(matchLength, text.length);

matches.push(firstPart);

regex = /\.filter\((.*?)\)/g;
while ((match = regex.exec(rest)) != null) {
  matches.push(match[1]);
}
log(matches);

Looking for a better solution.

  • 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-05-13T20:38:30+00:00Added an answer on May 13, 2026 at 8:38 pm

    This will match the single example you posted:

    <html>
      <body>
        <script type="text/javascript">
          text = '#container a.filter(.top).filter(.bottom).filter(.middle)';
          matches = text.match(/^[^.]*|\.[^.)]*(?=\))/g);
          document.write(matches);
        </script>
      </body>
    </html>
    

    which produces:

    #container a,.top,.bottom,.middle 
    

    EDIT

    Here’s a short explanation:

    ^         # match the beginning of the input
    [^.]*     # match any character other than '.' and repeat it zero or more times
              #
    |         # OR
              #
    \.        # match the character '.'
    [^.)]*    # match any character other than '.' and ')' and repeat it zero or more times
    (?=       # start positive look ahead
      \)      #   match the character ')'
    )         # end positive look ahead
    

    EDIT part II

    The regex looks for two types of character sequences:

    1. one ore more characters starting from the start of the string up to the first ., the regex: ^[^.]*
    2. or it matches a character sequence starting with a . followed by zero or more characters other than . and ), \.[^.)]*, but must have a ) ahead of it: (?=\)). This last requirement causes .filter not to match.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

text = I fixed bug #1234 and #7895 regex = /#(\d*)/ m = regex.match(text)
Text : aaaa Pattern : aa then will two match: aa(0,1), aa(2,3) if I
alt text http://home.elka.pw.edu.pl/~pkolodzi/Capture.PNG I have created the IAdder interface with two methods: PassA and
For text links, I have: CSS: a:link {color: #3366a9; text-decoration: none} a:hover {border-bottom: 1px
TEXT: R:\Everybody\OlegB\DiskCleaner\1\NewsFeed\Regional\Bray People_2010-04-14_v3.zip REGEX: (?<titleid>.*)_(?<issuedate>(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]))_v(?<layoutver>[0-9]*) I need apply REGEX to the following
System.Text.RegularExpressions.Regex(#*#) is this correct..!? my text can be like #abc1234+as00# etc. ie, anything between
the text: aaa the regex: a{2} the answer of notepad++ (v5.9.6.2 (UNICODE)): Can't find
Text is disappearing from the bottom of a RichEdit control window and I'd like
text = 'ticket number #1234 and #8976 '; r = /#(\d+)/g; var match =
text = urllib.urlopen('www.text.com').read() frase = re.search(your text here(.*), text).group() With these code, I get

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.