Dino
Dino

Reputation: 1457

Regex get first letter of a word before a specific word (php)

I have the following string in php:

$text = "This price excludes vat and blah blah blah ......";

and the start of regex :

preg_match("/(--not sure what goes here--)(?: vat)/", $text, $vatStatus);

Basically I would like to get the first letter of the word before vat (in this case the letter 'e').

In advance thanks for the help.

PS. the solution needs to be specifically in regex and not any other PHP functions.

Thanks

Upvotes: 1

Views: 267

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

/\b(\w)\w*?(?: vat)/

This should capture your first letter.

Upvotes: 3

Related Questions