繁体   English   中英

php使用preg_replace替换此字符串

[英]php using preg_replace to replace this string

我要替换此字符串第一个单词1 / 4W可能不同字符W可能是大写或小写

<?php
$str="1/4W this is string"; // 1/4W can be 1/16W, 1/2W, 1W,2w
$str=preg_replace(("/^\d.W/", "", $str);
var_dump($str);

我已经测试过,但我认为这并不准确

使用此正则表达式: ^\\d+(?:/\\d+)?w

$str="1/4W this is string"; // 1/4W can be 1/16W, 1/2W, 1W,2w
$str=preg_replace(("~^\d+(?:/\d+)?w~i", "", $str);

说明:

~       : regex delimiter
  ^     : start of string
  \d+   : 1 or more digits
  (?:   : start non capture group
    /   : a slash
    \d+ : 1 or more digits
  )?    : end group, optional
  w     : w
~i      : regex delimiter, case insensitive

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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