It seems that REGEX wasn't really the solution.
Instead I wrote multiple SQL functions that do the job:
CREATE FUNCTION [dbo].[KeywordMatches]
(
@String nvarchar(1000),
@Keywords nvarchar(1000),
@Seperator text
)
RETURNS INT
AS
BEGIN
DECLARE @Count int = 0;
DECLARE @Keyword varchar(1000);
DECLARE KeywordsCursor CURSOR FOR
SELECT *
FROM [dbo].StringSplit(@Keywords, @Seperator)
OPEN KeywordsCursor
FETCH NEXT FROM KeywordsCursor INTO @Keyword
WHILE @@FETCH_STATUS = 0
BEGIN
IF @String LIKE '%' + @Keyword + '%'
SET @Count += 1
FETCH NEXT FROM KeywordsCursor INTO @Keyword
END
CLOSE KeywordsCursor
DEALLOCATE KeywordsCursor
RETURN @Count
END
And (fallback for server 2016 split_string):
CREATE FUNCTION [dbo].[StringSplit]
(
@SeperatedWords nvarchar(1000),
@Seperator char
)
RETURNS @Words TABLE
(
Word nvarchar(1000)
)
AS
BEGIN
DECLARE @Position int = -1
SET @SeperatedWords += @Seperator
WHILE (@Position > 0 OR @Position = -1)
BEGIN
SET @SeperatedWords = SUBSTRING(@SeperatedWords, @Position + 1, LEN(@SeperatedWords) - @Position + 1)
SET @Position = CHARINDEX(@Seperator, @SeperatedWords)
/* Only add words that have a length bigger then 0 */
IF @Position > 1
/* Add the word to the table */
INSERT INTO @Words(Word) VALUES(LEFT(@SeperatedWords, @Position - 1))
END
RETURN
END
Usage:
SELECT Id, Title, [dbo].KeywordMatches(Title, 'blue red green', ' ') AS Matches
FROM Questions
ORDER BY Matches DESC, Date DESC
Above query orders by the amount of keywords found in the title and date.
I also read about full text search which is probably faster then this solution.