替换引号但保持英寸

I have text like: Senkatel Maximus 10.1" "White"

I would like to strip the quotes but keep the quote in the inch specification 10.1"

I tried using regex but it does not support variable length negative lookaheads

This: Senkatel Maximus 10.1" "White"

Should become: Senkatel Maximus 10.1" White

I need it as a general solution to stripping quotes without killing the inches in the text, so things like Senkatel Maximus 10.1" "Moonlight blue" and "Senkatel Maximus 10.1"" should also work if possible.

I think you might try this one:

"(\S(?:\s(?:\d+(?:\.\d+)?)"|[^"])+\S)"

and replace with $1.

I tested it on some of the samples lying about. regex101 demo.

EDIT:

If you have to remove quotes from strings like Dims: A" x B" as well (i.e. only numbers followed by double quotes have to be kept, unless in situations like "Film: 300", then you can use a regex a bit like SmokeyPHP's and adding a part I made above to give this:

(^|[^0-9])"((\b\d+(?:\.\d+)?"|[^"])+)"

Some samples have been tested here. (Note the were added on the demo because the regex was being tested on several strings and can be removed when testing on a string by string basis).

Looks like the job can be done with

preg_replace('/"(\S*?)"/', '$1', $string);

This removes the quotes from around any non-whitespace part of the string. Assuming at least one whitespace character appears between a single quote (which should remain) and any pairs of quotes (which should be removed) and also that the pairs of quotes do not include any whitespace it should work fine.

The following works for most situations mentioned on this page:

$newStr = preg_replace('#(^|[^0-9])"([^"]+)"#','$1$2',$str);

(Some) Test results:

"test" Senkatel "woo69" 2"-5" Maximus 10.1" "White"
test Senkatel woo69 2"-5" Maximus 10.1" White

Product: "Senkatel Maximus 10.1""
Product: Senkatel Maximus 10.1"

Dims: 4" x 6"
Dims: 4" x 6"

"Film: 300"
Film: 300

Issues will arise if there are inches in the middle of the string such as "Senkatel 10.1" Maximus" - at which point a much more complex set of code is required. This is probably the simplest code for the most function.

this removes any qoute that isnt directly after a number

preg_replace('/([^0-9])"/', '$1', $string);

but if the text is something like this: Senkatel Maximus 10.1" "White 1000" it would become: Senkatel Maximus 10.1" White 1000"

it just really hard to distinguish between a number withing quotes and an inch specification