vscode-regex icon indicating copy to clipboard operation
vscode-regex copied to clipboard

Add Go language support for regex preview

Open Copilot opened this issue 7 months ago • 0 comments

This PR adds support for Go language regex patterns to the VS Code Regex Previewer extension.

Changes Made

Go Regex Pattern Support

Added detection and preview support for Go's regexp package functions:

  • regexp.MustCompile("pattern")
  • regexp.Compile("pattern")
  • regexp.CompilePOSIX("pattern")

Supports both regular quoted strings and raw string literals (backticks).

Example Usage

The extension now recognizes and provides previews for Go regex patterns like:

package main

import "regexp"

func main() {
    // Email validation
    emailRegex := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)
    
    // Phone number with quoted string
    phoneRegex := regexp.Compile("^\\d{3}-\\d{3}-\\d{4}$")
    
    // POSIX character classes
    posixRegex := regexp.CompilePOSIX("^[[:alpha:]]+$")
}

Technical Implementation

  • Added Go-specific regex pattern to match regexp.* function calls
  • Updated language activation events to include Go files
  • Enhanced createRegexMatch() function to handle Go's different capture group structure
  • Go patterns don't use inline flags (unlike JavaScript/PHP), so flags are handled appropriately

Testing

Verified the implementation correctly:

  • Detects all three regexp functions (MustCompile, Compile, CompilePOSIX)
  • Handles both quoted strings and raw string literals
  • Produces valid JavaScript RegExp objects for the preview functionality
  • Works seamlessly with existing toggle and preview features

Fixes the feature request to add Go language support to the regex previewer.

Created from VS Code via the GitHub Pull Request extension.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Sep 05 '25 12:09 Copilot