Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 17, 2025

This PR introduces a comprehensive browser-based playground for the fancy-regex crate, compiled to WebAssembly (WASM). The playground provides an interactive interface for testing and exploring advanced regex features like backreferences and lookaround assertions.

Features

🎯 Interactive Regex Testing

  • Real-time regex pattern testing with immediate visual feedback
  • Support for all fancy-regex features including backreferences, named capture groups, and lookaround assertions
  • Visual highlighting of matches and capture groups in the test text
  • Configurable regex flags (case-insensitive, multi-line, dot-matches-newline, ignore-whitespace)

🔍 Advanced Analysis Tools

  • Parse tree visualization showing the internal AST structure of regex patterns with proper flag consideration
  • Detailed analysis output displaying compilation information and optimization details with flag-aware processing
  • Clear error messages for invalid patterns, compilation errors, and runtime issues

⚡ Performance & UX

  • Configurable debounce delay (100ms-2000ms) to customize real-time update responsiveness
  • Responsive design that works well on desktop and mobile devices
  • Loading states and smooth transitions for better user experience
  • Clean CSS organization with proper styling separation

Technical Implementation

WASM Module (playground/src/lib.rs)

  • Rust wrapper exposing fancy-regex functionality to JavaScript via wasm-bindgen
  • Key functions: find_matches, find_captures, parse_regex, analyze_regex, is_match
  • Flag-aware parsing and analysis functions that respect regex configuration using parse_tree_with_flags
  • Proper named capture group resolution using regex's capture_names() method
  • Uses flag constants exported from main crate's internals module to avoid code duplication
  • Optimized build configuration with size optimization and LTO

Frontend (playground/web/)

  • Modern HTML5/CSS3/JavaScript interface with no external dependencies
  • Structured as a two-panel layout with input controls and results display
  • Enhanced UI with configurable settings and clean footer design
  • Comprehensive error handling and user feedback
  • Preserves line breaks in highlighted text output

Development & Deployment

  • Local development server with CORS headers for WASM (serve.py)
  • Automated build script (build.sh) with version injection from main Cargo.toml
  • GitHub Actions workflow for automatic deployment to GitHub Pages
  • Complete documentation and usage instructions

Example Usage

The playground demonstrates fancy-regex capabilities with examples like:

h(?=ello)           # Positive lookahead
(?<word>\w+)\s+\k<word>  # Named backreferences  
(\w+)\s+\1          # Numbered backreferences
\w+(?=\s+world)     # Word boundary with lookahead

Code Quality Improvements

  • Clean architecture: Removed unused functions and consolidated common patterns
  • Proper flag handling: Flag constants exported from main crate to ensure consistency
  • Enhanced capture groups: Named capture group resolution shows actual group names
  • UI improvements: Fixed scrolling issues, organized CSS, and improved visual layout
  • Automated versioning: Build script automatically extracts version from main Cargo.toml

Deployment

The playground can be deployed to GitHub Pages automatically via the included GitHub Actions workflow, making it accessible at https://fancy-regex.github.io/fancy-regex/.

This addition significantly enhances the accessibility of fancy-regex by providing an interactive way for users to learn and experiment with advanced regex features without requiring local Rust installation.


💡 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 browser-based interactive playground for fancy-regex using WASM Add browser-based WASM playground for fancy-regex with advanced features Aug 17, 2025
@Copilot Copilot AI requested a review from keith-hall August 17, 2025 14:02
Copilot finished work on behalf of keith-hall August 17, 2025 14:02
Copy link
Contributor

@keith-hall keith-hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good! A few things to fix and improve but this is a great start! 🎉

@Copilot Copilot AI changed the title Add browser-based WASM playground for fancy-regex with advanced features Add browser-based WASM playground for fancy-regex with enhanced configurability and proper flag handling Aug 17, 2025
@Copilot Copilot AI requested a review from keith-hall August 17, 2025 20:16
Copilot finished work on behalf of keith-hall August 17, 2025 20:16
Copy link
Contributor

@keith-hall keith-hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more changes needed. In particular it makes sense to promote code-reuse where possible and ensure that documentation is up-to-date.

…e footer info, automate version

Co-authored-by: keith-hall <[email protected]>
@Copilot Copilot AI requested a review from keith-hall August 17, 2025 21:06
Copilot finished work on behalf of keith-hall August 17, 2025 21:06
Copy link
Contributor

@keith-hall keith-hall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more small comments, keep up the good work!

@Copilot Copilot AI requested a review from keith-hall August 18, 2025 11:19
Copilot finished work on behalf of keith-hall August 18, 2025 11:19
@keith-hall keith-hall marked this pull request as ready for review August 19, 2025 02:57
@keith-hall keith-hall requested a review from robinst August 29, 2025 05:19
Copy link
Contributor

@robinst robinst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done a quick pass and added some comments. Haven't looked through the JS and HTML in detail yet.

uses: actions/checkout@v5

- name: Setup Rust
uses: actions-rs/toolchain@v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is no longer maintained, we should use e.g. https://github.com/dtolnay/rust-toolchain instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, updated

wasm-pack build --target web --out-dir pkg --release
cp -r pkg/ web/
touch web/.nojekyll
rm web/pkg/.gitignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Maybe it should be excluded somewhere else?

Copy link
Contributor

@keith-hall keith-hall Aug 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub Action for deploying to GitHub Pages respects .gitignore, but we don't want to commit the compiled WASM stuff to git normally - just for the gh-pages branch. So this was the easiest solution I could think of, maybe there is a better way...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was still confused why the .gitignore is there in the first place, but now ran this locally. Even other files like README.md are there:

❯ ls -a web/pkg/
./                                   fancy_regex_playground_bg.wasm.d.ts  package.json
../                                  fancy_regex_playground.d.ts          README.md
.gitignore                           fancy_regex_playground.js
fancy_regex_playground_bg.wasm       LICENSE

Maybe instead of doing cp -r pkg/ web/ we could just do cp -r pkg/fancy_regex* web/pkg/? Ah but then pkg would need to be not ignored 🤔. Maybe it's fine the way it is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to gh-pages, as it deploys the whole page (clean: true).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this crate going to be published when we run cargo publish in the root of the repository? If yes, can we exclude it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question 🙂 I did a cargo publish --dry-run on the root of the repository and it only wanted to publish fancy-regex, not the playground 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this is for. If for local development, we don't need the version stuff.. And if so, maybe the README should just defer to this one.. Or maybe we just leave the stuff in the readme and get rid of this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's for local development, and I updated CI/CD to re-use it too, to make it easier to maintain and be confident that the GitHub Actions work as expected. I therefore removed the manual instructions in the readme.

Copy link
Contributor

@robinst robinst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments. Still some things we could improve with the styling and UI, but I think it's good enough to merge once comments are addressed!

- Named capture groups (`(?<name>...)` and `\k<name>`)
- Lookahead and lookbehind assertions
- All other fancy-regex features
- **Real-time Highlighting**: Visual highlighting of matches and capture groups in the test text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having tried it out, it doesn't actually highlight capture groups, only matches?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, I have now corrected the readme

<input type="checkbox" id="flag-ignore-whitespace">
<label for="flag-ignore-whitespace">Ignore whitespace</label>
</div>
<div class="flag-group" style="display: none;">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display: none; is one way to remove this 😆.. Can you clean this and the corresponding code up?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

</div>

<div class="input-group">
<label for="debounce-delay">Update Delay (ms):</label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this really needs to be configurable in the UI? I would probably remove.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed :)

padding: 1rem;
border-radius: 4px;
white-space: pre-wrap;
font-family: 'Courier New', monospace;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why they have a different monospace font here. In general the fonts are bit all over the place currently (e.g. the blue buttons have a different font from the rest). I think we should have:

  • Set a generic non-monospace font for all the UI stuff (including the buttons)
  • Only use monospace for the input and result text boxes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<div class="panel-header">Input</div>
<div class="panel-content">
<div class="input-group">
<label for="regex-input">Regular Expression:</label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use "Title Case" anywhere, but instead just "Sentence case", so e.g. "Regular expression:", "Case insensitive" etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done :)

</head>
<body>
<div class="header">
<h1>🎯 fancy-regex Playground</h1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the emoji personally.. Was wondering if we could use something that reminds us of regexes. Maybe /fancy-regex playground/?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea, done :)

change playground page heading and title
change from title case to sentence case in the playground html
move styles to separate stylesheet
- Set a generic non-monospace font for all the UI stuff (including the buttons)
- Only use monospace for the input and result text boxes (and parse tree/analysis output)
Make readme more accurate with regards to current features of the playground
remove debounce delay input
remove hidden unicode flag
@keith-hall keith-hall merged commit 0f6f611 into main Sep 12, 2025
9 checks passed
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.

3 participants