r/regex • u/Beautiful-Log5632 • 1d ago
Include underscore in ripgrep word boundary
\bWORD\b doesn't match _WORD_ because \b doesn't include _ so I miss a lot of matches. Is there something else I can use like \b that works like that?
r/regex • u/quixrick • Oct 23 '19
/R/REGEX POSTING RULES
Please read the following rules before posting. Following these guidelines will take a huge step in ensuring that we have all of the information we need to help you.
Thank you!
r/regex • u/Beautiful-Log5632 • 1d ago
\bWORD\b doesn't match _WORD_ because \b doesn't include _ so I miss a lot of matches. Is there something else I can use like \b that works like that?
r/regex • u/fasnoosh • 4d ago
In case you ask, my work does Chrome managed profiles/bookmarks, so yes it has to be Chrome
r/regex • u/DerPazzo • 6d ago
Hi,
#### not possible as explained by rainshifter ####
#### original flair was .NET ####
I want to create a huge regex to match exact word groups coming from a list of around 7k words.
It’s about chemical names and there are lots of repeated words at the end of the names. The names must always be exact matches and possible variations not on this list are not allowed. I thought about using backreferences wihtin the regex in order not to have to rewrite these words every time.
Will that even work?
Is this a good idea or will it slow down my search?
In the following example list I would like to use the first occurence of EXTRACT as a backreference for all following words within the pipe ending on EXTRACT. It’s mainly about back references for the endings as the start of the word groups is created as efficient as possible with pipes forking at every difference of a word:
\b(A(BIES (ALBA SEED EXTRACT|(BALSAMEA ((BALSAM )?EXTRACT|NEEDLE OIL)|KOREANA LEAF EXTRACT|SIBIRICA (NEEDLE )?OIL))|CACIA CATECHU (BARK POWDER|WOOD EXTRACT)))\b
Using brackets around the first occurence of EXTRACT creates backreference \4 but using it further down the regex does not seem to work. (see regex below)
\b(A(BIES (ALBA SEED (EXTRACT)|(BALSAMEA ((BALSAM )?EXTRACT|NEEDLE OIL)|KOREANA LEAF EXTRACT|SIBIRICA (NEEDLE )?OIL))|CACIA CATECHU (BARK POWDER|WOOD \4)))\b
List:
ABIES ALBA SEED EXTRACT
ABIES BALSAMEA BALSAM EXTRACT
ABIES BALSAMEA EXTRACT
ABIES BALSAMEA NEEDLE OIL
ABIES KOREANA LEAF EXTRACT
ABIES SIBIRICA NEEDLE OIL
ABIES SIBIRICA OIL
ACACIA CATECHU BARK POWDER
ACACIA CATECHU WOOD EXTRACT
r/regex • u/Large-Friend1415 • 13d ago
Enable HLS to view with audio, or disable this notification
Author here. The detection is per-language (e.g. a Groovy slashy string is not a JS literal), and edits flow both ways: change the pattern in the editor and the canvas follows, rework it visually and it lands back in your file. The flavor matters because engines genuinely disagree — I published the data: https://regexpilot.com/divergences. The extension is free; it pairs with a Mac app for the visual side.
The app you see on the right is is the visual editor you can try a demo on https://regexpilot.com
Note: the app is Mac only.
r/regex • u/NorwegianBarbie07 • 13d ago
r/regex • u/ajaydubey541997 • 15d ago
Hello!
A year or two ago I used a regex generator website where I pasted the match I wanted and it iterated over and let me select 1 character, or a group of characters and tell it if I'm looking for an exact match or alpha numeric or whatnot, then it added onto a field where the generated regex was being built for me. It underlined groups in different colours.
It was a dark mode website. Not sure it's dark by default of it used my system default. It also had a language selector before you started building. Really nice UI. I don't remember much more than that.
Would really appreciate if someone could help me remember 🙏
r/regex • u/Apocryphate • 16d ago
Apologies if this isn't the correct forum for a post like this.
I play a video game (Path of Exile II) which allows players to search various "containers" (like our storage) with basic terms or with regex strings (items that match the search criteria are highlighted in the container). I've developed an extremely limited understanding of some basic regex to solve problems as I go, but I'm currently stumped and looking for some guidance.
I would like to highlight items that contain at least 2 of 4 different terms. The 4 terms are:
tac
fra
har
nco
I thought I could pair these terms using quotes, and separate pairs with | but that isn't working. I'm not sure if this is because I'm not using regex properly or it's a limitation of the game's regex functionality. My attempt looked like this:
"tac""fra"|"tac""har"|"tac""nco"|"fra""har"|"fra""nco"|"har""nco"
----------
Here are 3 examples of items that I would like the regex to highlight:
Item 1
increased Stack size of Simulacrum Splinters
increased Fracturing Mirrors
Item 2
increased MirrorShards
increased Delirium Encounters
Item 3
increased Fracturing Mirrors
increased MirrorShards
----------
Here are 3 examples of items that I would like the regex to NOT highlight:
Item 1
increased Fracturing Mirrors
increased Pack Size
Item 2
increased MirrorShards
increased rarity of monsters
Item 3
increased Pack Size
increased rarity of monsters
r/regex • u/Ricktcher_Supernova • 25d ago
I'm trying to match (j|w)?[aeo]$ but only on the lines that start with [-].
I've tried making it a conditional, but I'm new and I don't really understand why it doesn't work...
ideally, it should leave the lines that don't start with [-] alone
r/regex • u/Tarnisher • Aug 01 '26
This is for posts here. I have an AutoMod set up that removes posts with fewer than 'X' characters.
Is there a way I can prevent those posts from being submitted to begin with?
r/regex • u/4RH1T3CT0R • Jul 26 '26
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/
r/regex • u/Dorindon • Jul 25 '26
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 • u/apollojuniper • Jul 24 '26

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 • u/younesWh • Jul 15 '26
/^[a-zA-Z( (?! ))à-öø-ÿœŒ]{2,40}$/gm
but this syntax I added in middle for space handling seems not working...
r/regex • u/Chaela911 • Jul 14 '26
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 • u/ja4nice • Jul 09 '26
How could I, using an added special character, join or split paragraphs as I mark them - using Sed 2.0 or Ssed.
r/regex • u/maiyannah • Jul 08 '26
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 • u/pedrulho • Jul 07 '26
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 • u/StartAutomating • Jul 01 '26
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.
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.
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.
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 • u/Federal_Bird1265 • Jun 23 '26
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 • u/Repulsive-Drive9568 • Jun 20 '26
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 • u/SpawnSnow • Jun 18 '26
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 • u/Gamegenie47 • Jun 16 '26
r/regex • u/d00mstroll • Jun 12 '26
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.
- 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 • u/iper_linuxiano • Jun 12 '26
Why no search engine allow jolly characters use? Does exist an Internet regex search engine?