Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 5, 2025

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 Copilot AI changed the title [WIP] add support for Go Add Go language support for regex preview Sep 5, 2025
Copilot finished work on behalf of chrmarti September 5, 2025 12:21
@Copilot Copilot AI requested a review from chrmarti September 5, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants