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

  • Home
  • SEARCH
  • 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 8703389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:51:28+00:00 2026-06-13T02:51:28+00:00

If someone has seen this question before, please link, perhaps I am searching the

  • 0

If someone has seen this question before, please link, perhaps I am searching the wrong things. I get nothing but results for parsing css files. Basically, I have an array of selectors, something like

[".thislink", "#myid"].

I’m looking to pass any string selector formatted like css3 selectors, ex:

a.thislink:not(.ignore)[href^=http://]

into a .match and split it out into an array of selectors, ideally:

[a, .thislink, :not(.ignore), [href^=http://]]

that I can loop through. I would then use that same breakdown on any :not() selectors to get a second array of “not”, which I can match against my original array of individual selectors.

Tag, class, ID, attr, and :not selectors should be all I need. I can figure out how to break down the [attr=val] and :not(selectorshere) myself, I think.

PS:
I know it would be easy to match my original array values in the string selector, however, I don’t actually have an array of selectors. It would take several paragraphs to explain why exactly I’m doing it this way, so just trust me, I can’t do it =)

  • 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-13T02:51:28+00:00Added an answer on June 13, 2026 at 2:51 am

    Just in case you won’t succeed in finding a sufficient regex, may I suggest a JavaScript parser generator like PEG.js*. There’s an online version of PEG.js that allows you to tinker with the grammar, then download the parser once satisfied with the result.

    [ * ] PEG – Parsing Expression Grammar

    For help with the grammar you should consult the W3C’s working draft on CSS3 syntax W3C’s recommendation on Selectors Level 3.

    I took the time and played around and came up with a reduced grammar for a single selector (element/id/attr/class/pseudo). You’d want to go over it and refine it here and there, probably.

    /*
     * PEG.js grammar
     */
    start      = element? hash? (class / attr / pseudo)*
    element    = '*' / ident
    
    ident      = i:(nmstart) j:(nmchar*) {return i + j.join('');}
    hash       = h:('#' ident) {return h.join('');}
    class      = c:('.' ident) {return c.join('');}
    attr       = a:('[' (b:[^\]]+ {return b.join('');}) ']') {return a.join('');}
    pseudo     = p:(':' function) {return p.join('');}
    
    nmstart    = [a-z] / nonascii
    nmchar     = [a-z0-9-] / nonascii
    function   = f:(ident '(' body ')') {return f.join('');}
    body       = b:[^\)]+ {return b.join('');}
    
    nonascii   = [\x80-\xff]
    _          = [ \t\n\r]+ {return '';}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems with LD_LIBRARY_PATH at link time (this question has nothing to do
I know this question has been discussed before, but i am interested in doing
Probably someone has already asked this question but I'm not sure what I'm looking
I have a strange problem in PHP, hopefully someone has seen this before. I
Someone has asked the exact same question in April, without any answer. But since
I'm hoping someone has run into this sort of problem before, and can give
Sorry if this question has been asked 100 times before, unfortunately, i haven't found
This question is marked as a community wiki, and is subjective, but please don't
Yes, I know this question has been asked 1000 times before... here is the
I know this could be seen as subjective off-the-cuff (thus a poor question), but

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.