如何使用以下字符串中的`RegExp`废弃此字符串中的数据`Lamp In Box`

时间:2022-07-05 16:19:29

How to scrap Data Lamp In Box in this string using RegExp in following string -

如何使用以下字符串中的RegExp废弃此字符串中的数据灯泡 -

I want to scrapped 1 Units using regexp

我想用regexp报废1个单位

I have write below regexp but its not working.

我写了下面的regexp,但它不起作用。

Regexp - Lamp In Box: '(.*)(s)<\/td>

Regexp - Lamp In Box:'(。*)(s)<\ / td>

`<td><b>Price:</b></td>         <td>
                                                                                        <br />Free Ground Shipping&nbsp;<span class="show_free_shipping" style="color:red;">[?]</span>
                                <br />Ship From United States
                            </td>
                        </tr>
                                                <tr>
                            <td><b>Availability:</b></td>
                            <td>
                                                        <b style="color:blue;">In Stock</b>
                                                        </td>
                        </tr>
                        <tr>
                            <td><b>Lamp In Box:</b></td>
                            <td>1 Unit(s)</td>
                        </tr>

                                            </table>
`

2 个解决方案

#1


2  

For catching the number of Lamp In Box you can try the next:

要获取Lamp In Box的数量,您可以尝试下一个:

$string = <<your input string>>;
$pattern = '/Lamp In Box:.*\s*.*?(\d+) Unit\(s\)/i';
preg_match($pattern, $string, $result);

The $result would contain what you need.

$ result将包含您需要的内容。

#2


0  

You can try the next regular expression, if I correctly understand you:
/(<td>).*Lamp In Box:.*\s*.*?(<\/td>)/i

So, you can test this by:

你可以尝试下一个正则表达式,如果我正确理解你:/().*Lamp In Box:。* \ s *。*?(<\ / td>)/ i所以你可以通过:

$string = <<your input string>>;
$pattern = '/(<td>).*Lamp In Box:.*\s*.*?(<\/td>)/i';
$replacement = '$1$2';
echo preg_replace($pattern, $replacement, $string);

This replaces all that are inside of <td></td> which contains Lamp In Box

这将取代包含Lamp In Box的 内的所有内容

#1


2  

For catching the number of Lamp In Box you can try the next:

要获取Lamp In Box的数量,您可以尝试下一个:

$string = <<your input string>>;
$pattern = '/Lamp In Box:.*\s*.*?(\d+) Unit\(s\)/i';
preg_match($pattern, $string, $result);

The $result would contain what you need.

$ result将包含您需要的内容。

#2


0  

You can try the next regular expression, if I correctly understand you:
/(<td>).*Lamp In Box:.*\s*.*?(<\/td>)/i

So, you can test this by:

你可以尝试下一个正则表达式,如果我正确理解你:/().*Lamp In Box:。* \ s *。*?(<\ / td>)/ i所以你可以通过:

$string = <<your input string>>;
$pattern = '/(<td>).*Lamp In Box:.*\s*.*?(<\/td>)/i';
$replacement = '$1$2';
echo preg_replace($pattern, $replacement, $string);

This replaces all that are inside of <td></td> which contains Lamp In Box

这将取代包含Lamp In Box的 内的所有内容