Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205372

`r`: Efficiently identifying identical parts of two strings w/o prior knowledge of the pattern?

$
0
0

I'm looking for an efficient solution to the following problem:

a <- "TestStringA"
b <- "TeststringB"
magical_string_processing(a, b)
> [1] "Test""tring"

In essence: How do I detect identical parts of strings without knowing them pre hoc? How to do this operating from known patterns and using regular expressions is easy, but without the knowledge?

<--EDIT--> Answers have been given and I'll explore them, but in the meantime stackoverflow tags gave me nomenclature pointers and I explored e.g. https://stackoverflow.com/a/50705861/2103880, which leads to

a <- "TestStringA"
b <- c(paste(LETTERS, collapse = ""), "TeststringB")
stringdist::amatch(a,b, method = "lcs", maxDist = Inf)
[1] 2

The matching string is thus nicely identified, but the actual substring not extracted ...

Thank you for any pointers.


Viewing all articles
Browse latest Browse all 205372

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>