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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:19:07+00:00 2026-06-16T14:19:07+00:00

I need to extract 3 fields from a snippet of text. I’ve got a

  • 0

I need to extract 3 fields from a snippet of text. I’ve got a regex that extracts 2 of those fields – file and extension. I don’t know how to extract the content text and I don’t have a strategy for matching all characters except ‘not a pattern’.

The pattern is: var regex_file = /<!--<\|(.*)\.(.*)\|>-->/g,

Also, I’m not sure a regex is the best way to do this. I considered the string method split: split(regex_file)

But I don’t think there is a way to keep the delimiter one splits on. It just returns the the content between the delimiter. Also, I don’t think there is a way to loop through split() as I did through exec() below.

What is the best way to extract these 3 fields from text in the structure below. Further below is what I have so far.

Text Structure

<!--<|file.extension|>-->

// 1-10k of content text

<!--<|file.extension|>-->

// 1-10k of content text

<!--<|file.extension|>-->

// 1-10k of content text

First Attempt

    /*addNodes
    **
    **
    **
    */
    function addNodes(text) {
        var regex_file = /<!--<\|(.*)\.(.*)\|>-->/g,
            arr_file;

        while ((arr_file = regex_file.exec(text)) !== null) {
            arr_file[1] // holds file 
            arr_file[2] // holds extension
            arr_file[3] // need content here
        }
    }

Additional Criteria:

IE10+, FF10+, Safari5+, Chrome20+…Major Modern Browsers.

  • 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-16T14:19:08+00:00Added an answer on June 16, 2026 at 2:19 pm

    You were pretty close. The delimiter can be kept with regex:

    s = "<!--<|file.extension|>--> // 1-10k of content text <!--<|file.extension|>--> // 1-10k of content text <!--<|file.extension|>--> // 1-10k of content text"
    a = s.split(/<!--<\|([^.]*)(\.[^|]*)\|>-->/g)
    for (i = 1; i < a.length; i += 3) {
      console.log('result:');
      console.log('  "'+a[i]  +'"');
      console.log('  "'+a[i+1]+'"');
      console.log('  "'+a[i+2]+'"');
    }
    

    output:

    result:
      "file"
      ".extension"
      " // 1-10k of content text "
    result:
      "file"
      ".extension"
      " // 1-10k of content text "
    result:
      "file"
      ".extension"
      " // 1-10k of content text"
    

    I was able to manually test it successfully for ie9, chrome23 on windows and chrome23, safari6, ff6 on on osx10.

    I also threw it on browsershots.org and execution was successful for these versions:

    firefox: 3.6.27 4.0.1 5.0.1 1.5.0.12 10.0.2 6.0.1 11.0 11.0 12.0 13.0 14.0.1 17.0 7.0.1 15.0 16.0 2.0.0.20 8.0.1 9.0.1 18.0 17.0 19.0 3.6.28 16.0 9.0.1 10.0.2 17.0 6.0.2 7.0.1 8.0 12.0 14.0.1 13.0.1 4.0.1 15.0 5.0.1 3.0.10 19.0 18.0

    msie: 10.0

    safari: 3.2.3 5.1.7 5.1.7 6.0 5.0

    chrome: 7.0.517.44 23.0.1271.101 17.0.963.56 8.0.552.224 17.0.963.56 22.0.1229.26 23.0.1251.2 22.0.1312.45 9.0.597.107 11.0.696.77 10.0.612.1 12.0.742.112 13.0.782.218 14.0.835.202 15.0.874.106 18.0.1025.33 19.0.1041.0 20.0.1132.57 21.0.1180.89 24.0.1312.45 23.0.1271.97 16.0.912.77 2.0.172.31 6.0.472.63

    It was not successful for:
    chrome 20.0.1132.47 on ubuntu-12.04-lts

    or versions of msie < 10

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

Sidebar

Related Questions

I need to extract a few fields of data from many lines of text.
I need to extract multiple text/dropdown list fields from an asp.net form and format
Need to extract .co.uk urls from a file with lots of entries, some .com
I need to extract financial price data from a binary file. This price data
I've got and sql express database I need to extract some data from. I
I need to use an awk script to extract some information from a file.
I need to create a process that will extract the changes from a table
I need to extract a value from a hidden HTML field, have somewhat figured
I need to extract the URL's from the php datas, how can i achieve
I need to extract this text: Line 1 text. Line 2 text. Line 2

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.