Condition.
There are uppercase alaphabet items
items = [ "FUCAMVLNDI", "KXRMGDPOHU", "GPMKEUFLQJ",
"YHBURQPOFM", "VKURNBXTIH", "IGLOTVNPEY", "SLCGRJOPYB",
"HUDGIFNTPM", "EPHLCQZFOR", "TYDIAVUQZW", "KTYBZPXSHG",
"CWXMLTFDJI", "ERCJSWPFYH", "TQSHIKRCMJ", "JHBOYCFWAK",
"NPVAMTLXBQ", "BIWAUNPSOT", "TQZARXMSLH", "JLYDFHWMTN",
"XODHNVFCWM", "EWZFKXRIVM", "KVEWZRXIMA"
- There are given string which is 10 length, uppercase alphabet, like
BIWAUNPSOT
each calleditem
above - Each Alphabet in
item
is a meta data ( or property ), not just a alphabet. - So i want to find a
item
initems
usingregex
which presents condition of the most matching a given meta data of eachitem
- Intersection of two string
- If
YHBURQPOFM
matchesIGLOTVNPEY
.Y, O, P
Three conditions are satisfied
- In order to know the
most
satisfied condition, I thought i need to use{ }
operator because it's countable so that i can find the most matching for eachitem
with some logic. but it's hard to make regex to me. something wrong. - I would find
item
ofitems
usingmatch
method likeitems.toString().match(item_regex);
- My problem is
item_regex
- But is there another good way to find the
most
matching item? not usingregex
?
What i did
for ( let i = 0; i < items.length; i ++){
// make RegExp using each item
const regex = new RegExp('\\b[' + items[i] + ']{' + increase + '}\\w+', 'g');
const matchedList = items.toString().match(regex)
if ( matchedList === null ) {
// the previous one was the most matched condition
// So I thought that ( increase - 1 ) is the most matched condition
} else {
increase++;
i=0;
}
}
The example of regex what i thought is
\b[item]{increase}\w+
It might be something like
\b[YHBURQPOFM]{7}\w+
But never mind. I think this is totally wrong
So My Question is
What is the best
regex
which meet the condition i mentioned- I need
2~n items
with the most matching , - I need the number for the most matching ( How many match each item, it can be 1~10 because, the given string is 10 length )
with the code above, I can get
2~n items
throughmatchedList
I can get number for the most matching through
increase
,{ } operator
- I'm trying to match each alphabet in any other. ex)
ABCDEFGHIJ
andAXBCDEFGHI
is the match = 9 but alsoJIHGFEDCBA
andAXBCDEFGHI
is the match = 9
- I need
- Was it wrong approach? i mean, Using regex is a bad idea for this solution?
Edit
The most matching means
Intersection with two string. For example
If YHBURQPOFM
matches IGLOTVNPEY
. Y, O, P
, Three conditions are satisfied
So I would search every item
for the whole items
so that i can find the most matching
they can be 3 couples with satisfying 7 conditions, they can be 2 couples with satisfying 8 conditions
If 0 couples with satisfying 9 conditions, then 8 is the most matching