简体   繁体   中英

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

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

这应该抓住你的第一封信。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM