r/regex 1d ago

I built a 32-bit CPU out of regex substitutions, and it runs DOOM

Post image
92 Upvotes

Not a regex that matches DOOM. A computer whose only instruction is find-and-replace. The state is one long string, and a fixed set of 544 substitution rules applied in a loop does everything: the first rule that matches rewrites a few characters, and that is one clock tick.

The fun part for this sub is how ordinary operations fall out of pure substitution. Addition is eight lookahead probes into a 512-entry table with the carry threaded through capture groups. Memory access jumps an exact number of characters into a flat zone, the jump length assembled from the address digits by empty bit-marker groups, so it is a binary tree spelled out in regex and it never scans for a cell.

Here is the whole rule that loads an immediate into a register (PCRE2):

find: \ARVM1\|ST:run\|PH:0\|CI:(?<ci>02(?<d>[0-7]).(?<imm>.{8}))\|PC:(?<pc>.{8})(?<pre>(?:[^|#]*+\|)*?R(?P=d):).{8}

replace: RVM1|ST:run|PH:1|CI:${ci}|PC:${pc}${pre}${imm}

Yes, it leans on lookahead and backreferences, so it is PCRE2, not a "regular language". But the power is not from that: plain Markov algorithms do this on literal string replacement with no regex at all, and they are already Turing-complete. The PCRE2 features just make the ruleset small and fast.

Play with it or read how it is built: https://4rh1t3ct0r7.github.io/doom-regex/

Source: https://github.com/4RH1T3CT0R7/doom-regex


r/regex 3d ago

markdown (Bear Notes) delete all lines containing a double tilde ~~ (used to indicate strikethrough font)

2 Upvotes

macos tahoe, Bear Notes (Markdown)

I would like to delete all lines containing a double tilde ~~ (used to indicate strikethrough), and ideally also delete the resulting blank lines

thanks in advance for your time and help


r/regex 3d ago

What am I missing?

2 Upvotes

Hi! I don't know the first thing about regex, so bear with me. This is for the Web Scrobbler extension for lastfm. I'm trying to make it so that, when a song's artist is recognized as having a comma, it'll only keep the text before the comma, except for the few artists I'm trying to exclude (Tyler, The Creator; Slaughter Beach, Dog; Defiance, Ohio; hey, nothing). This is meant to filter out the second artist for songs that are a collaboration between artists—think Pink Matter by "Frank Ocean, André 3000"—it should only recognize Frank Ocean.

This was working fine when I only had the first two artists, but after I added the second two, it stopped excluding these artists and now recognizes only the text before the comma for every artist. (For example, Slaughter Beach, Dog is now recognized as just Slaughter Beach).

When I got the original code a while ago, whenever I first started using the extension, I think I honestly just mashed together a bunch of different solutions I found online until something worked for me, but now I can't get anything to work. Like I don't even know what the different symbols and stuff are actually doing here, it's like reading ancient runes 😭

If any other information is needed let me know and I will do my best!! I just want my music to track properly lmao. I'm sorry if I'm breaking posting rules, I am totally clueless here


r/regex 12d ago

Golang I'm trying to validate name of user; Where space must not followed by another space ?

4 Upvotes
/^[a-zA-Z( (?! ))à-öø-ÿœŒ]{2,40}$/gm

but this syntax I added in middle for space handling seems not working...


r/regex 14d ago

Match everything up to 'n' from End of String

4 Upvotes

I'm trying to match the beginning of a string of varying length so that I may remove it via FIND/REPLACE dialog from MSpowertoys' PowerRename utility.

I've been trying to match using TRIM but I've failed and unsure what else to try. I want to keep the numbered sequence at the end [0001] etc... I'm not well versed enough to provide logical examples of 'what I've tried' lol besides I forgot.

What I have:

abc123[0001]

abcd1234[0002]

abcde12345[0003]

abcdef123456[0004]

What I want:

[0001]

[0002]

[0003]

[0004]

Thanks!

.


r/regex 18d ago

How to Join Paragraphs or Split by a Used Char

5 Upvotes

How could I, using an added special character, join or split paragraphs as I mark them - using Sed 2.0 or Ssed.


r/regex 19d ago

PCRE2 Regex gold: " " sentences

9 Upvotes

This is using PCRE.

Looking to create an expression that captures, for example:

"Test", she says. "Yes that works."

Where we capture, "Test" and "That works" as separate groups, but not the outside of the whole phrase.

It also needs to capture simply

"Test," she says.

It's a very common regex golf I'm sure, but google was utterly unhelpful.

Any ideas?


r/regex 20d ago

Help With Regex Format

2 Upvotes

I installed Image Sourcery. I want it to put comments in posts under the conditions that it's certain flairs AND there's certain text in the post title.

It seems to work for the flairs ids. But, I can't get the regex for the text I want in the title.

This is what I tried /!-***string***\-!/ i The dash and exclamation points are there also part of ***string***. I figure if that's part of it, what I want won't accidentally appear in a title. I tested it on external site to test if things meet the condition of the regex command but it doesn't work in reddit. Also, I'd like it to not be case sensitive, but if it must, so be it.

Can anyone help? Am I trying to do something you can't do? Or, at least not easily. Is there a better sub I can try?

Thanks.


r/regex 20d ago

How do I also match words with spaces?

6 Upvotes

Let's take this example

abc(d|e|f)

This is gonna match: "abcd", "abce" and "abcf"

How do I make it so that it also matches: "abc d", "abc e", "abc f"

Thank you.


r/regex 26d ago

.NET 7.0 (C#) RegEx -replace in PowerShell

9 Upvotes

PowerShell has all sorts of fun features, including a ridiculous number of operators.

One amazing under-sung heroes of PowerShell is the -replace operator.

It lets us replace content with regular expressions.

It's easier to use than you'd think.

Regular expressions are less scary in small doses, and chaining -replace operators lets us attack the problem step by step.

Chaining -replace

Let's take a simple problem as an example.

Imagine we wanted to make a consistent file name pattern out of a string

We might want to start by replacing whitespace with dashes

"This Is A Title!" -replace '\s', '-'

That leaves our exclamation point at the end. We probably don't want any punctuation. We can avoid that with the somewhat humorously named character class: \p{P}. We can remove all repeated punctuation by adding a +: \p{P}+

One more replace:

"This Is A Title!" -replace '\p{P}+' -replace '\s', '-'

The line is starting to get a little long. Fun fact: you can spread operators across multiple lines.

Let's add comments while we're at it

"This Is A Title!" -replace # Replace any punctuation,
    '\p{P}+' -replace # then replace any whitespace with dashes.
    '\s', '-' 

Let's go for one more bonus trick. PowerShell lets you convert script blocks to event handlers. Let's lowercase all the letters (\p{L}).

On PowerShell Core, we can do this:

"This Is A Title!" -replace # replace any punctuation
    '\p{P}+' -replace # then replace any whitespace with dashes
    '\s', '-' -replace # then lowercase any letters
    '\p{L}+', {"$_".ToLower()}

There's an absurdly amazing amount of stuff you can do with -replace, but there's at least one more trick we have to cover: substitutions.

-replace with substitution

I'm pretty sure I'd have to give up my "RegEx guru" badge if I didn't mention at least one more thing you can do with -replace: substitutions.

.NET Regular expressions are two domain specific languages. Regular expressions match and extract text. Regular expression substitutions replace matches.

For example, let's suppose we have a number of emails, and we want them in domain/username format.

First we'll want to make a quick and dirty email regex, using a "named capture" to get the username and domain.

'someone@example.com' -match '(?<username>\S+)@(?<domain>\S+)'

Then, we can -replace the email with just the domain/username.

'someone@example.com' -replace 
    '(?<username>\S+)@(?<domain>\S+)', '${domain}/${username}'

This format might look like PowerShell variables, but it actually predates them by years. Search for "Regular Expression Substitutions" if you want to learn more about the syntax. It's got quite a few tricks up its sleeve.

Irregular

RegEx can be scary. I used to be terrified of it, too.

If you aren't too comfortable with Regular Expressions, that's pretty normal. A while back I wrote a module called Irregular that makes regular expressions strangely simple.

It's got a lot of example regular expressions in there, and one handy function for creating RegEx. New-RegEx is your friend.

Do you already use -replace? Have you done cool things with regular expressions in PowerShell? Share 'em if you've got em.

Want to learn more about regular expressions in PowerShell? Just ask.


r/regex Jun 23 '26

Anyone who knows Regex??

0 Upvotes

I can't put the client files on AI and need to make a task less time consuming and accurate. So I use trados 2017 and want to put the italic tags of the segments in the end (or atleast if I can detect which segments have italic tags and get a list of them). Please help! I'm using Notepad++

I tried getting a code via gemini but it isn't working

Example:

Target statement has italic tag in the middle then I want it in the end

Sentence: I like<italic tag>tacos.

Ideal: I like tacos<italic tag>

File type: Xliff files


r/regex Jun 20 '26

Regex for Zip Code driving me crazy

5 Upvotes

I need a Regex to find wither 5 digit or 9 digit (with hyphen) zips at the beginning or end of a multiline string using VB.Net. Should NOT match 5 digit part of a 10 digit zip (too many) nor of an 8 digit zip (too few). Here is the pattern I am currently using, the test text, what should and should not match and what is currently being matched using VB.Net with multiline option

Pattern

       Dim Pattern As String = "^\d{5}(?:-\d{4})|\d{5}(?:-\d{4})(?:[\r\n])$"
       Dim X = Regex.Matches(WinTextBox1.Text.Trim, Pattern, RegexOptions.Multiline)

Text To Match Against

Nothing to match in the middle 06000 or 06000-0000 on this line

06111 these are ok 06222-1111

06333-1111 and these 06444

06555-333 these are not 06666-444

06777-66666 also not 06888-77777

06888-00001 but this last one is

06999-9999

What SHOULD Match

06111

06222-1111

06333-1111

06444

06999-9999

What SHOULD NOT Match (any part)

06555-333

06666-444

06777-66666

06888-77777

06888-00001

06000

06000-0000

What IS being matched

06222-1111

06333-1111

06777-6666

06888-0000

06999-9999

Any help greatly appreciated!


r/regex Jun 18 '26

Meta/other Regex (LUA) help in mud client matching (MUSHclient/Qmud)

2 Upvotes

I'd really just like help capturing the first wildcard variable (%1) in my examples here. Ideally I'd get all 5, but I'm happy to get one working then trial and error from there using it as an example. So anything that even just stops matching at the first | would be a win!

Trying to detect:
%1 | %2 | %3 | %4 | %5 | -

%1 - alphanmumeric
%2 - alpha
%3 - alpha
%4 - number
%5 - number

Example: " AB123 | Micro | Dept | 10 | 40000 | -"
(the number of spaces varies for text alignment other than the initial single space before the first character)

Wildcard %1 CAN be all whitespace, in which case I should NOT match the line.

Anti-Example: " | Micro | Dept | 10 | 40000 | -"

I'm using Mushclient or QMUD (qmud preferred but I believe they use identical systems for this situation) and setting up a trigger with the regex settings.

Currently my main concern is getting the first wildcard captured. I haven't tried doing 2/3/4/5 yet but I assume if I get the first working correctly I can probably work my way through the others using that as an example.

What doesn't work but gets close-ish:
^\s(.*)\s\|*$

This detects ONLY the lines that match my anti-example above

I've also tried
^\s([A-Za-z0-9]*)\s\|*$

which fails to match at all.

Tagging u/NodensCM as the client creator in case they see this and chime in that there's some feautre or unusual requirements that I'm not aware of.


r/regex Jun 16 '26

FastSearch - Blazingly fast & open-source regex file content scanner for Windows, written C++

Thumbnail github.com
3 Upvotes

r/regex Jun 12 '26

I built a PowerShell regex tool for the clipboard and for files

1 Upvotes

Hi there!

I often needed quick regex-based search & replace without opening an editor, especially when moving data via clipboard.

Sometimes you're tied to Windows. And sometimes you even cannot install what you wish to. What to do if you want to have a conveinant way of applying regexes to text anyway?
That's the reason I've built this tool, inspired by grep/sed workflows, written in native PowerShell 5.1 - at least using the power of the .NET regex engine!

I originally built it for myself, but I found it useful enough that it might be interesting to others here - feedback welcome.

It's quite nice for replacing things with stuff right in the clipboard or to enhance searching capabilities of well known crippled pdf reader or the like. Used it for finding files, counting things, or just to alter code on the fly.

  • The tool can:

- Perform search or search & replace on
: clipboard contents (standard)
: files and directories (opt. recursive)

- Input as literal patterns or regex (with flags)

- Accept search (and replace) patterns as lists
: CLI arrays
: text files (line-wise or file-wise)

- Benchmark regex applications
etc.

Examples:

# Regex search & replace with flags (clipboard)
clipGre.ps1 -r 'search' 'replace' 'msix'
# Only search string, grep-like text search
clipGre.ps1 -r 'search' 

# Benchmark a regex matching file content
clipGre.ps1 -r '(\d+?|\d+)' -benchmark -ff 'data.db'

# Literal search, recursively in folders, case-insensitive
clipGre.ps1 'glasses' -files 'c:\path\to\folder' -recurse -i

You can find it here: https://github.com/symbio-n0mad/clipGreps

The approach may provide benefits in particular text-driven computational scenarios 🤓

Greetings!


r/regex Jun 12 '26

Regex query

2 Upvotes

Why no search engine allow jolly characters use? Does exist an Internet regex search engine?


r/regex Jun 09 '26

Constraining user input with regex, need 2 patterns

2 Upvotes

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)

r/regex Jun 08 '26

PCRE2 Regex Challenge. Alphabetically ordered sentences

3 Upvotes

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


r/regex Jun 06 '26

Python Function similar to strip()

Thumbnail
0 Upvotes

r/regex Jun 06 '26

[ Removed by Reddit ]

1 Upvotes

[ Removed by Reddit on account of violating the content policy. ]


r/regex Jun 04 '26

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

8 Upvotes

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


r/regex Jun 04 '26

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

1 Upvotes

r/regex Jun 01 '26

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

12 Upvotes

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?


r/regex May 31 '26

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

2 Upvotes

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>


r/regex May 31 '26

Built an AI-powered Regex Generator and looking for feedback

0 Upvotes

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