✅ Regex pattern to match unique words each with 3 unique characters

Given a multiline input text:
abc
aaaa
bcde
acd
abc
abc
xyz
abc
aaaa
bcde
acd
abc
abc
xyz
I am looking for a regex pattern that matches unique words each consists of exactly 3 unique characters. The expected output:
acd
xyz
acd
xyz
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
Jimmacle
Jimmacle10mo ago
what have you tried?
cap5lut
cap5lut10mo ago
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
Jimmacle
Jimmacle10mo ago
my suggestion is also not to use regex for this use the right tool for the problem
cap5lut
cap5lut10mo ago
as far as i know its simply not expressable as regex what u r trying to do
Jimmacle
Jimmacle10mo ago
way simpler to put the lines in a hashset first then remove entries with duplicate characters (or the other way around)
cap5lut
cap5lut10mo ago
unless u want to or all possible combinations
Jimmacle
Jimmacle10mo ago
did an interviewer ask this question? i'd give them the same answer, regex isn't the right tool
cap5lut
cap5lut10mo ago
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 urself
Jimmacle
Jimmacle10mo ago
a 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?
cap5lut
cap5lut10mo ago
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
Jimmacle
Jimmacle10mo ago
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?
cap5lut
cap5lut10mo ago
regex is pattern matching, what u want to do is semantics, thats nothing regex is used for
i like chatgpt
i like chatgptOP10mo ago
I don't know it is solvable or not with regex.
Jimmacle
Jimmacle10mo ago
so maybe don't insist on getting a regex solution
cap5lut
cap5lut10mo ago
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 oring all possible combinations, and have fun doing that with unicode
Jimmacle
Jimmacle10mo ago
it would be easier to help if you asked about actual practice questions for your test
cap5lut
cap5lut10mo ago
feels to me like that they created this problem for themselve to figure out how to solve it
Jimmacle
Jimmacle10mo ago
well, asking chatgpt definitely isn't the right way then :KEKW:
cap5lut
cap5lut10mo ago
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)
Jimmacle
Jimmacle10mo ago
@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?
Jimmacle
Jimmacle10mo ago
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
cap5lut
cap5lut10mo ago
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"
mindhardt
mindhardt10mo ago
I really thought @cap5lut and @jIMMACLE are just two schizos talking to the voices :kekw:
cap5lut
cap5lut10mo ago
nah, that wasnt the case 😂
Want results from more Discord servers?
Add your server