neophp / regexbuilder-package
Dev-only regex tester with live match highlighting for NeoPHP
Package info
github.com/NeoPHP-Dev/neo-regexbuilder-package
Language:JavaScript
pkg:composer/neophp/regexbuilder-package
Requires
- php: >=8.5
README
A dev-only regex tester for NeoPHP. Write a pattern, test it against sample text, and see matches highlighted live — entirely client-side, no server round-trip needed to evaluate a match.
Structure
regexbuilder-package/
├── composer.json
├── README.md
└── src/
├── NeoRegexBuilderPackage.php
├── Middleware/
│ └── DevOnlyMiddleware.php
├── Controllers/
│ └── RegexBuilderController.php
├── Assets/
│ ├── css/regexbuilder.css
│ └── js/regexbuilder.js
└── Templates/
├── components/
│ └── RegexBuilder.macro.html.twig
└── pages/
└── builder.html.twig
Dev-only, by design
The standalone page's route is protected by DevOnlyMiddleware, which
checks Config/app.config.php's environment key. Outside
environment: dev, it returns a blocked response.
The RegexBuilder macro itself has no such restriction, since it makes
no server calls — if you embed it in your own page (e.g. inside
neo-admin-package), guard that page the same way you'd guard any other
dev tool page in your project.
Installation
php bin/neo package:require neophp/regexbuilder-package --project=MyProject
Register it in the project's Config/app.config.php:
return [ // ... 'packages' => [ \Vendor\NeoPHP\RegexBuilderPackage\NeoRegexBuilderPackage::class, ], ];
No configuration file, no migration.
Usage
Standalone page
Visit /_regexbuilder/ (only reachable in dev). Type a pattern and
flags, edit the test string, and matches highlight live below.
Embedding in your own page
{% import '@RegexBuilder/components/RegexBuilder.macro.html.twig' as RegexBuilder %}
<link rel="stylesheet" href="/packages-assets/RegexBuilder/css/regexbuilder.css">
{{ RegexBuilder.render() }}
<script src="/packages-assets/RegexBuilder/js/regexbuilder.js"></script>
RegexBuilder.render(instanceId = 'rb') accepts an optional
instanceId to avoid collisions if rendered more than once on the same
page.
PHP vs JavaScript regex differences
This package uses JavaScript's native RegExp, not PHP's PCRE
(preg_match). The two dialects are very similar for everyday patterns,
but not identical — some PCRE-specific syntax (certain lookbehind
variations, possessive quantifiers, recursive patterns) is not supported
by JavaScript's engine. A pattern that behaves correctly here should
work in PHP for the vast majority of common cases, but always verify
directly in your PHP code for anything advanced.
Theming
Every visual value is a CSS custom property scoped to .rb-layout:
.rb-layout { --rb-accent: #6366f1; --rb-bg: #161923; --rb-bg-alt: #1b2030; --rb-border: #2d3342; --rb-text: #e5e7eb; --rb-text-muted: #9ca3af; --rb-mark-bg: #fbbf24; }
License
MIT