Question: Let's say I have the following string:

```
var str = "I like barbeque at dawn";

```

I want pairs of all words which are separated by a space. This can be achieved via the following regular expression:

```
  var regex = /[a-zA-Z]+ [a-zA-Z]+/g;
  str.match(regex);

```

This results in:

```
["I like", "barbeque at"]

```

But what if I want ALL permutations of the pairs? The regular expression fails, because it only matches any given word onces. For example, this is what I want:

```
["I like", "like barbeque", "barbeque at", "at dawn"]

```

I know I can use the recursive backtracking pattern to generate permutations. Do regular expressions have the power to create these types of pairs for me?

Answer: 
My DB had latin1 encoding:

```
SELECT @@character_set_database, @@collation_database;

```

Fix the DB first:

```
foreach table: ALTER TABLE @table CONVERT TO CHARACTER SET utf8;
ALTER DATABASE javabg CHARACTER SET utf8 COLLATE utf8_unicode_ci;

```

make sure all connections are in utf8 - edit my.cnf:

```
[mysqld]
#mist: set default encoding to utf-8
init-connect='SET NAMES utf8'
character-set-server = utf8
collation-server = utf8_general_ci

```
Caution: `init-connect` is ignored when you connect as `root`.

`ALTER TABLE @table CONVERT TO CHARACTER SET utf8;` applies only if you have proper latin1 encodings of data in the table now. If you have put non-Western-European text in latin1 fields, the solution is other. Please do

```
SELECT col, HEX(col) ...

```

to see what is in there now.

If the output is to be on a web page, you need to check that the meta tag specifies utf8.