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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:25:16+00:00 2026-05-26T17:25:16+00:00

I am in need for a regex in Javascript. I have a string: ‘*window.some1.some\.2.(a.b

  • 0

I am in need for a regex in Javascript. I have a string:

'*window.some1.some\.2.(a.b + ")" ? cc\.c : d.n [a.b, cc\.c]).some\.3.(this.o.p ? ".mike." [ff\.]).some5'

I want to split this string by periods such that I get an array:

[
    '*window',
    'some1',
    'some\.2',   //ignore the . because it's escaped
    '(a.b ? cc\.c : d.n [a.b, cc\.c])',  //ignore everything inside ()
    'some\.3',
    '(this.o.p ? ".mike." [ff\.])',
    'some5'
]

What regex will do this?

  • 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-26T17:25:17+00:00Added an answer on May 26, 2026 at 5:25 pm
    var string = '*window.some1.some\\.2.(a.b + ")" ? cc\\.c : d.n [a.b, cc\\.c]).some\\.3.(this.o.p ? ".mike." [ff\\.]).some5';
    var pattern = /(?:\((?:(['"])\)\1|[^)]+?)+\)+|\\\.|[^.]+?)+/g;
    var result = string.match(pattern);
    result = Array.apply(null, result); //Convert RegExp match to an Array
    

    Fiddle: http://jsfiddle.net/66Zfh/3/
    Explanation of the RegExp. Match a consecutive set of characters, satisfying:

    /             Start of RegExp literal
    (?:            Create a group without reference (example: say, group A)
       \(          `(` character
       (?:         Create a group without reference (example: say, group B)
          (['"])     ONE `'` OR `"`, group 1, referable through `\1` (inside RE)
          \)         `)` character
          \1         The character as matched at group 1, either `'` or `"`
         |          OR
          [^)]+?     Any non-`)` character, at least once (see below)
       )+          End of group (B). Let this group occur at least once
      |           OR
       \\\.        `\.` (escaped backslash and dot, because they're special chars)
      |           OR
       [^.]+?      Any non-`.` character, at least once (see below)
    )+            End of group (A). Let this group occur at least once
    /g           "End of RegExp, global flag"
            /*Summary: Match everything which is not satisfying the split-by-dot
                     condition as specified by the OP*/
    

    There’s a difference between + and +?. A single plus attempts to match as much characters as possible, while a +? matches only these characters which are necessary to get the RegExp match. Example: 123 using \d+? > 1 and \d+ > 123.

    The String.match method performs a global match, because of the /g, global flag. The match function with the g flag returns an array consisting of all matches subsequences.

    When the g flag is omitted, only the first match will be selected. The array will then consist of the following elements:

    Index 0: <Whole match>
    Index 1: <Group 1>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string in javascript like this: some string 27 or it could
I need a regex (JavaScript) which will extract shortforms from a string for example
I am trying to match the following string in Javascript Regex PC123456 This is
I have another Javascript regex conundrum... (apologies if this is a bit long-winded -
I have this regex on Javascript var myS = 00 - ??:??:?? - a;
i need your help with an regex in Javascript, again. Sometimes i have empty
I am trying to validate a password string with javascript and need some help
I have a string that looks like this: <td width=308>Services Needed: <a href=javascript:void(null); title=weekly
I need a Regex that will match a java method declaration. I have come
I need a Regex Statement (run in c#) that will take a string containing

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.