0

I can't find an expression which can remove all letters on both sides of a line.

Data sample:

Valencia 7x16/5x114.3 D71.6 ET48 Dark

I need to remove all letters on sides such as Valencia and Dark, so the output from previous string should be:

7x16/5x114.3 D71.6 ET48

I tried using the following expression but it didn't work:

[^x./ETD\s0-9] 
4

2 回答 2

1

您在技术上不需要正则表达式:

$output = trim($input,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ");

但这可能会更容易。

$output = preg_replace("/^\S+\s|\s\S+$/","",$input);
于 2013-08-17T10:17:53.613 回答
1

描述

该表达式将:

  • 删除字符串开头或结尾处的所有字母,直到第一个空格字符

正则表达式:^[a-z]*\s|\s[a-z]*$

替换为:空字符串

在此处输入图像描述

例子

现场演示

示例文本

Valencia 7x16/5x114.3 D71.6 ET48 Dark

更换后

7x16/5x114.3 D71.6 ET48
于 2013-08-17T14:06:45.413 回答