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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:20:03+00:00 2026-05-31T10:20:03+00:00

As a personal project, trying to learn Go(lang) by applying it to something, I

  • 0

As a personal project, trying to learn Go(lang) by applying it to something, I am writing an EMCAScript/JavaScript “compiler”; all it will (initially) do is allow you to include other .js files.

Functionality aside, I am pulling my hair out trying to figure out the regexp package. Here is the snippet that does not seem to be doing what I want it to:

// Note: "lines" is an array of strings.

var includeRegex, _ = regexp.Compile("^[ \t]*include[(]{1}\"([^\"]+)\"[)]{1};")
for _, line := range lines {
   var isInclude = includeRegex.Match([]byte(line))
   if isInclude {
      var includeFile = includeRegex.FindString(line)
      fmt.Println("INCLUDE", includeFile)
   } else {
      // ...
   }

I have already stumbled across Go’s subset of regular expressions, hence why the regex does not read as ^\s*include\("([^"]+)"\);. I have already tested both the preferred, and the Go-style regex, in RegexPal, and both definitely work. The match just never seems to occurr; what am I doing wrong?

For what it’s worth, the include() statement I am trying to parse looks like so:

include("somefile.js");

EDIT: For what it’s worth, I am keeping the code here.

  • 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-31T10:20:05+00:00Added an answer on May 31, 2026 at 10:20 am

    This seems to work with the latest weekly

    package main
    
    import (
            "fmt"
            "log"
            "regexp"
            "strings"
    )
    
    func main() {
            includeRegex, err := regexp.Compile(`^\s*include\("(\\\"|[^"])+"\);`)
            if err != nil {
                    log.Fatal(err)
            }
    
            for _, line := range strings.Split(`
    foo
    include "abc.def"
    include("file.js");
                include "me\"to\""
                include("please\"!\"");
            nothing here          
    `, "\n") {
                    if includeRegex.Match([]byte(line)) {
                            includeFile := includeRegex.FindString(line)
                            fmt.Println("INCLUDE", includeFile)
                    } else {
                            fmt.Printf("no match for \"%s\"\n", line)
                    }
            }
    }
    

    Output:

    $ go build && ./tmp 
    no match for ""
    no match for "foo"
    no match for "include "abc.def""
    INCLUDE include("file.js");
    no match for "        include "me\"to\"""
    INCLUDE       include("please\"!\"");
    no match for "  nothing here      "
    no match for ""
    $ 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Boost::Fusion (Boost v1.42.0) in a personal project. I get
I am involved in a personal project which will require pretty extensive knowledge of
I would like to start a personal project that will give me a lot
I recently started a new personal project to learn Entity Framework. My end goal
I've been gathering ideas for my personal project in CSS/JavaScript/XHTML. The idea is to
as a personal project I am trying to write a wiki with the help
I am trying to commit some updates to my personal project on google code
Background: I'm trying to build a web app (as a personal project using modern
I've sort of been trying EBS on my personal project tasks, but two things
I'm trying to implement a simple web application server as a personal project to

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.