English 中文(简体)
删除整个字句,如果之后有具体特性的话
原标题:Remove whole word if followed by specific character

我的发言是:

your string here, please/do it by yourself.

我愿在鞭 before之前删除这个词,最后要删除:

your string here, do it by yourself.

我的法典是:

$string =  your string here, please/do it by yourself. ;
$parsed = preg_replace("s*w+s+(?:w/)",   , $string);

它没有做任何事情(甚至没有改动就印刷插图)。

问题回答

你们的监管者没有限制,只是说了。

“区域或更多空间,一个或多个字体,一个或一个以上空间,其次是<代码>w 然后是/

$parsed = preg_replace("(w+/)","",$string);
echo $parsed;

另一种不依赖规章的解决办法:

<?php

$example =  your string here, please/do it by yourself. ;
$expected =  your string here, do it by yourself. ;

$slashPos = strpos($example,  / );
$spacePos = strrpos($example,    , -1 * $slashPos);

$string1 = substr($example, 0, $spacePos + 1); // Add 1 here to not remove space
$string2 = substr($example, (strlen($example) - $slashPos - 1) * -1); // Subtract 1 here to remove /

$result = $string1 . $string2;

var_dump(assert($expected === $result));

https://3v4l.org/XVruS

产出5.6.38 - 7.3.0

bool(真实)

参考资料:

rel=“nofollow noreferer”> http://php.net/manual/de/Function.strpos.php

http://php.net/manual/de/Function.strrpos.php>rel=“nofollow noreferer”> http://php.net/manual/de/Function.strrpos.php

http://php.net/manual/de/function.substr.php

Niet the Dar Absol说的话。 你们需要划界。 此外,你(甚至有划界人)说,“0-无限的白色空间,然后是1个定点字体,然后是1个定点空间,然后是湿/.。

That s not what you want. You want to remove the word before the slash - and the slash. You would need something like @w+/@ (where the @ sybmols are the delimiters) and replace that by , e.g. preg_replace( @w+/@ , , $string); to replace any word followed by a slash by nothing.





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签