Question: Can somebody help me to getting the last word from a text which contains only letters.

I should use regex I think...

For example:

```
100 r St Lazare, 75009 PARIS

```

I need the word `PARIS`

Answer: 
If you want a **pure** regex solution, you can use

```
([a-z]+)$|^.*\b([a-z]+)\b

```

as your regex.  

(Again, replace `[a-z]` with `[^\s\d]` if you're dealing with non-ascii chars)  

[Demo @ regex101](http://regex101.com/r/yC4vK5)

---

Essentially there are two cases:

1. A word consists only of letters *or* numbers. So there won't be a word like `Im1Word`.  

If this is the case, I'd go for

```
/([a-z]+)$|([a-z]+)[^a-z]+$/i

```

This will match `PARIS` in `100 r St Lazare, 75009 PARIS` and,  

for another example it will match `test` in `just a test 7509`.  

See the [demo @ regex101](http://regex101.com/r/pL9gU3) (the `g` and `m` flags are just to match on multiple lines, so you see everything it would match).
2. A word consists of letters *and* numbers. There may be words like `Im1Word`.  

The above regex won't be enough and I would do this with some more logic in the code:

```
$input = "100 r St Lazare, 75009 PARIS 123 abc123 123";
$words = explode(' ', $input);

for($i = count($words)-1; $i >= 0; $i--) {
    if(preg_match("/\b[a-z]+\b/i",$words[$i]) == 1) {
        echo "Match: " . $words[$i];
        break;
    }
}

```

Essentially, we split the string by a space and iterate over each element from the end until the beginning. Whenever an element matches `\b[a-z]+\b` we found last word consisting only of letters.  

[Example @ ideone](http://ideone.com/TKqEQs)

Now, if you have any non-ascii characters both of the above solutions will fail.  

You need to change both regexes:

1. `([^\s\d]+)$|([^\s\d]+)[\s\d]+$`
2. `"/\b[^\s\d]+\b/i"`

This way you will match non-ascii words, too.
you may try

```
$text = "100 r St Lazare, 75009 PARIS";
$exploded = explode(" ",$text);
echo $exploded[count($exploded)-1]

```