r/regex

▲ 2 r/regex

Constraining user input with regex, need 2 patterns

I am using a regex to try and constrain user input into a textbox. I need the first character to be A-Za-z OR an asterisk (*) and the remaining characters to be A-Za-z only. I have a pattern, but it is allowing the * anywhere. I am not sure how to fix it. Using in .Net desktop application.

Current Regex

"^[^A-Za-z\*][^A-Za-z]*$"

Should allow "*Bob Smith" or "Bob Smith"

Should prevent" "Bob *Smith", "*Bob *Smith" or Bob Smith*"

Currently is allowing all of the above. It's like the second pattern is not being evaluated. Any help appreciated... Usage below (any user input that doesn't match pattern should be removed)

Regex.Replace(OriginalText, "^[^A-Za-z\*][^A-Za-z]*$", String.Empty)
reddit.com
u/Repulsive-Drive9568 — 12 hours ago
▲ 2 r/regex

Regex Challenge. Alphabetically ordered sentences

Challenge if anyone wants to have a go.

The objective is as follows:

Match full sentences which will start and end on separate lines if and only if all the words appear in alphabetical order. Reading from left to write

Rules:

1. Words must be considered fully, meaning the ordering of words with the same starting letters have to be ordered by the standard.

2. For words with multiple letter the same at the start the first letter of difference counted from the left and appearing in the same position in both words (ie. roofing and rock differ at the 3rd letter from the left of each.

3. Shorter words come first alphabetically if they share all their letters in the same order with a longer word.

4. Your solution can use any flavour you wish, I have tagged it PCRE2 since that is what I wrote my solution in.

Here are four sample sentences you can use for testing purposes

>

all bearded men must shave sometimes - in AO match

very vulgar vultures want withering waste - not in AO should not match

like most musty parlours placeing pointless queries quietly rather ruined the wager -
AO match

beet beetroot being bent bruised bashed but barely boiled - not in AO should not match

The best tip I have for this one is remembering that only two words need to be out of order for the whole sentence to be. Meaning at least 2 words in an out of order sentence must be beside each other. I'd say the difficultly is intermediate to advanced was a lot of fun have a go and share your solutions, I will share mine in a few days

reddit.com
u/FewCall1913 — 2 days ago
▲ 8 r/regex

RegexPilot — Test regexes against the actual engines, not JavaScript approximations

Hi r/regex,

First of all if this is not the place for me to post this feel free say so and I'll remove the post, I just wanted to share with you and receive some feedback on what features people here would love in a tool like this, or even negative criticism. I've built it in the first place for myself but it might be useful for others especially those learning regular expressions or people who are more visual thinkers like myself.

I built RegexPilot, a macOS regex tool to solve a problem that kept biting me: many regex testers advertise support for multiple flavors, but internally route everything through a JavaScript engine and emulate the rest. That means patterns can appear to work in the tester and then fail in production. Or AI generating a regex that later turns out to be not entirely what I was looking for.

interface

RegexPilot runs each flavor against its actual interpreter/runtime:

  • Python → CPython
  • Ruby → MRI/Onigmo
  • Perl → Microperl 5.36.3
  • PHP → Native PCRE
  • Java → OpenJDK (GraalVM-compiled)
  • C# → .NET 9
  • Additional languages available as well (see website)

Typical execution time is around 1–3 ms.

Other features:

  • Visual regex builder with railroad diagrams
  • Live match testing and replacement preview
  • Capture-group inspection
  • AST-based editor (edits modify the syntax tree and regenerate the pattern)
  • Regex library/snippets
  • Optional AI assistance (bring your own API key or run locally via Ollama / LM Studio)

Privacy notes:

  • Voice dictation runs entirely on-device (Whisper Tiny)
  • No analytics, tracking, or account requirement
  • The only network access is license validation for Pro users

Website: https://regexpilot.com

A couple of questions for the regex crowd:

  1. Have you been bitten by flavor differences that online testers failed to catch?
  2. Which regex engine quirks or debugging features would you most like to see surfaced visually?
  3. Are there any language runtimes I should prioritize adding next?

I’d love feedback from people who regularly work across multiple regex flavors.

The roadmap is also on the website if you'd like to see what I have planned next. There's even a demo on the site so you don't even have to download the app or have OS X to try some of the basic things

reddit.com
u/Large-Friend1415 — 5 days ago
▲ 1 r/regex

Can any one suggesst how to start with regex as many edr products are requiring regex for creating IOA rule .

reddit.com
u/Zishaan1423 — 6 days ago
▲ 12 r/regex+1 crossposts

I wrote a RegEx alternative that's actually readable, please share your thoughts

Hey everyone, I'd like to share an open source project I've been working on that I think you may find it useful for your projects: enhex (Enhanced Expression) – a human-readable language for writing regular expressions. This isn't a new pattern-matching system; it adds a readable layer over RegEx patterns to keep them descriptive and maintainable.

Here is an example of the difference in a complex URL pattern:

^https?:\/\/(?:[a-zA-Z\d-]+\.)+[a-z]{2,10}(?::\d{2,5})?(?:\/[^\s\?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$

(Please tell me, can you actually "read" above pattern?)

Instead, you can write this in you code or a .enhex file:

start
+ "http" + optional("s") + "://"
+ one_or_more(
    non_capturing(one_or_more(letter | digit | dash)
    + ".")
)
+ tld() # Top Level Domain (EnhEx internal preset)
+ optional(
    non_capturing(":" + between(2, 5, digit))
)
+ optional(
    non_capturing("/" + zero_or_more(not(whitespace | "?" | "#")))
)
+ optional(
    non_capturing("?" + zero_or_more(not(whitespace | "#")))
)
+ optional(
    non_capturing("#" + zero_or_more(not(whitespace)))
)
+ end

Its GitHub repo is available here for complete information: https://github.com/mkh-user/enhex

It's available in Rust (Crates.io), Python (PyPI), and JS (npm) with the same behavior (Rust is core).

I'm currently working on a VSCode extension for highlighting, autocomplete, and live preview. Do you have any ideas to share?

u/Soggy-Usual-4898 — 9 days ago
▲ 2 r/regex

Challenge: “Complete the chevrons” (For the fun)

This one is moderately easy if you know the syntax. :)

Let’s say not all the chevrons have been written, sometimes it has been the case, sometimes not…

First, what should match:

<1 (the chevron on the right has been forgotten)
2> (the chevron on the left has been forgotten)
<3> (Even if you don’t do anything, it should be considered)

Then, what shouldn’t match:

4 (there’s no chevron at all, it’s impossible to tell if the chevrons should be there)

So this is the challenge: change the writing to put one chevron on the left et one chevron on the right:

From: <<1 2> 3 <4>

To: <1> <2> 3 <4>

reddit.com
u/Chichmich — 10 days ago
▲ 2 r/regex

\*n* doesn't seem to work correctly in search strings.

According to my Regular Expression Pocket Reference:

>*n* Contains the results of the nth earlier submatch. Valid in either a regex pattern, or a replacement string.

Yet in vim:

:%s/\(paraNumber"&gt;\)\([0-9\.]*\)\(\t\=\)\(\n.*\)\(\(\n.*\)\{-\}\n\t.*paraNumber"&gt;\)\2/\1\2\3\4\5\2\t/gc

treats the \2 in the search string as a repetion of what's in the second pair of parentheses instead of the earlier submatch.

Am I misinterperating the manual or is vim doing something wrong? Anyway how do I get what the manual seems to say I should get.

reddit.com
u/OalBlunkont — 10 days ago
▲ 5 r/regex

Url parsing

I've looked for a regex to parse and group all kind of url address but couldn't find complete one so made one and leave it here. Be free to say if anythings missing, I'll update it

u/Pawl_Evian — 12 days ago
▲ 3 r/regex+1 crossposts

Built an AI-powered Regex Generator and looking for feedback

Built a free AI-powered Regex Generator 🚀

I created RegexAI because I found myself repeatedly searching Stack Overflow and tweaking regex patterns for simple validations.

Instead of writing regex manually, you can describe what you need in plain English and get a ready-to-use pattern instantly.

Some examples:

  • Email validation
  • URLs
  • Phone numbers
  • Password rules
  • Custom text matching

Looking for honest feedback from developers:

https://www.regexai.dev

What's the most annoying regex you've had to write recently?

r/webdev r/programming r/SideProject r/InternetIsBeautiful

reddit.com
u/ElectronicAthlete249 — 12 days ago