Q:

How to extract the similarities between two strings

I have two strings in two different sentences: 
string 1: 30 mutation alanine for valine
string 2: alanine at position 30
is there away to find the similarities between them as it is clear
they both have 30 and alanine using regular expressions for example?

A:

One thing you could do is check for words that appear in both strings:
$ comm -12 <(sed 's/ /\n/g' <<<$str1 | sort) <(sed 's/ /\n/g' <<<$str2 | sort )
30
alanine

Explanation

The comm command compares files. With the -1 and -2 flags, it will print those lines that are found in both files.
sed 's/ /\n/g' <<<$str1 | sort : This simply replaces all spaces with newlines in $str1, printing to standard output which is then passed through sort because comm needs its input files to be sorted. For more on the <<<$var format, see Bash: Here Strings.  
The <(command) format is called process substitution, more on that here.

The final result of the command above will be a list of all words that appear in both strings.

A:

Maybe wdiff can help you? Put the strings into two files and then compare them with wdiff:
echo "30 mutation alanine for valine" > file1
echo "alanine at position 30" > file2
wdiff -t file1 file2

Screenshot of the output:

