How to find repeated character blocks within a string?

Asked

Viewed 50 times

-1

I am doing a college job and in order to continue I need to take a message that has been given and find out if there are repeated blocks of characters inside that message and which is the block. Example: message= banana; I know you have a block of characters 'na' that repeats twice in the message. I would know to find a repeated character, but a character set I have no idea.

  • What have you tried?

  • So far I thought I’d take a slice of the string and compare it to the whole string. For example, I take an initial slice of three characters and compare to see if I find something that matches, if yes, I compare again but with a larger slice (of 4 characters), until the comparison returns nothing else. But this I thought considering that some block of characters at the beginning of the message will repeat.

1 answer

0

I credit that with the regular expression library "re" you can solve this your problem, if you want some help with the code you could pass examples of input that will be passed and what you expect to be the output.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.