简体   繁体   中英

Php - How to remove number from a specific string?

I need to remove a number only from a specific string. In particular:

$item = preg_replace('/\d+/u', '', $item);

but in this way it replaces all numbers from all strings. I instead need to remove only number after string 'team'.

How can I do this?

team2567 = team;
season1617 = season1617;

Thanks a lot!

使它像

$item = preg_replace('/team\d+/u', 'team', $item);

使用正向后看

$item = preg_replace('/(?<=team)\d+/u', '', $item);
 $str = 'In My Cart : 11 12 items';
 preg_match_all('!\d+!', $str, $matches);
 print_r($matches);

Do something like

$item = preg_replace('/team\d+/u', 'team', $item);

or with capturing group

$item = preg_replace('/(team)\d+/u', '$1', $item);

or with positive lookbehind

$item = preg_replace('/(?<=team)\d+/u', '', $item);

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