✅ Regex pattern to match unique words each with 3 unique characters
Given a multiline input text:
I am looking for a regex pattern that matches unique words each consists of exactly 3 unique characters.
The expected output:
Edit:
For new visitors, this question can actually be solved with
negative lookbehind
and negative lookahead
.
If you are in hurry, you can jump to https://discord.com/channels/143867839282020352/1204500978741673994/1204519081663926304
and return again to this message https://discord.com/channels/143867839282020352/1204500978741673994/1204500978741673994 in the future.
I may update with the solution. 🙂25 Replies
what have you tried?
thats something u shouldnt do with regex
?! i said do not use regex for this
u know the closest regex pattern string to validate an email address is ~4k characters long and is still not completely correct.
there are problems where regex fits and some where they dont
my suggestion is also not to use regex for this
use the right tool for the problem
as far as i know its simply not expressable as regex what u r trying to do
way simpler to put the lines in a hashset first then remove entries with duplicate characters (or the other way around)
unless u want to
or
all possible combinationsdid an interviewer ask this question?
i'd give them the same answer, regex isn't the right tool
u know if u would have a format like
abdasdc-123-xy2434z
and the requirements to have these unique chars per segment u would write a regex to find the segments and post process them with code
unless they expect the answer "u dont do it with a regex"
even if there is one i dont know of, it would be such a complex thing that its by far less performant than writing it in code urselfa business shouldn't care if you can write a complicated regex to solve a contrived problem, they should care that you can solve the problem using any tool at your disposal
it's like asking a carpenter to build a chair with nothing but an angle grinder
for an interview or for what?
yeah, but they wouldnt use problems to solve that aint solvable with regex
if u want to look at "advanced" regex stuff thats something like back referencing or recursion
can we clarify something
is this actually a question you expect to get, or is this something you made up without knowing if it's solvable or not?
regex is pattern matching, what u want to do is semantics, thats nothing regex is used for
I don't know it is solvable or not with regex.
so maybe don't insist on getting a regex solution
ever tried to play number guessing with it? dont trust that damn thing
i really did a lot with regex, but this seems impossible unless u r
or
ing all possible combinations, and have fun doing that with unicodeit would be easier to help if you asked about actual practice questions for your test
feels to me like that they created this problem for themselve to figure out how to solve it
well, asking chatgpt definitely isn't the right way then :KEKW:
who knows what it spits out, maybe its some garbage that can lead ur thoughts to something useful
but in 99% of the time it doesnt
either my network wiped or discord is slow, i meant to type 99%
ah now its updated
reminds me of an old job, there they had a pattern to name their files but over the years it changed, but they didnt rename the old ones
so the thoughtfully built regex wasnt enough to determine all the info from the filenames and then it was bruteforcing on the database entries
in the end it was still impossible to differentiate between some entries and the pathologists had to check the medical data to see what fits together
(it was anonymized data for a research project)
@talk is cheap, show me the code i really don't want to keep bringing this up, please stop deleting messages
it makes it impossible to read the thread after the fact
this server isn't just for you to ask questions then delete the conversation because you got your answer, it's a place for everyone to learn from all the questions being asked
that's not what i'm asking you to do
i'm asking you to stop deleting messages
can you do that?
cool, my time is too valuable to be wasted by your constantly poor behavior and i won't be putting any more effort into helping you
can't say i didn't try
oh wow they really deleted everything
in case u r reading this: what u asked for wasnt anything to be ashamed of if u felt that way
everyone asks "stupid" questions, not because they are stupid but because they dont YET have the knowledge
@talk is cheap, show me the code may i ask why u delete messages? u can dm me and i wont publicate them, i just want to understand
(by "them" i mean ur messages)
i take that as a "no"
I really thought @cap5lut and @jIMMACLE are just two schizos talking to the voices :kekw:
nah, that wasnt the case 😂