1

Say I have the below data

string data1 = "2014SP";
string data2 = "2014DP";
string data3 = "2014AP-S1"

Is there a way I can tell while comparing the strings that they follow a pattern which is say NumberWordSpecialCharacter etc. So in this case data1 and data2 have the same pattern and data3 is different.

I can do it using Regex if I have defined patterns, but I don't. I have a list of data which needs to be compared while incrementing with patterns which are not defined so maybe one comparison set is 213S-P12 and 2014S and the Second is S-P2015 and SP123.

halfer
  • 19,824
  • 17
  • 99
  • 186
SP1
  • 1,182
  • 3
  • 22
  • 47
  • 1
    First step would be to actually clearly specify what "pattern" means for your case. Than it should be trivial to compare patterns for each string. – Alexei Levenkov Sep 28 '16 at 01:54
  • Possible duplicate of [C# - Compare String Similarity](http://stackoverflow.com/questions/6944056/c-sharp-compare-string-similarity) – Mick Sep 28 '16 at 02:04
  • You need to provide a bunch of positive and negative examples if you hope to get any useful answer. – Enigmativity Sep 28 '16 at 02:07
  • This question is going to be a duplicate. There's either a known pattern, in which case there are hundreds of regex questions on stack overflow already. Or if there is no known pattern then the question "Compare String Similarity" question would be relevant – Mick Sep 28 '16 at 02:09

1 Answers1

0

The first idea pops into my head is you can try a simple pattern model by converting input string into a output integer. Such as: if it is a letter (or letter block), replace it with 1; number, replace it with 2; etc. Easy and efficient. I'm not sure this helps :)

uqji
  • 195
  • 1
  • 10
  • You obviously would use string as result, not integer - but indeed it is the idea of a standard approach: normalize values and than group originals by corresponding normalized value. I.e. `"2014AP-S1"` would map to `"ddddaasad"` (d - digit, a - alpha, s - special). – Alexei Levenkov Sep 28 '16 at 02:19