The Penultimate St
aitrocious.com
Bad bedtime storie
It's Called a Russ
What do you want f
The Tables Have Tu
APB is out for
I’m gonna take my
This end justifies
Sleeping with the You drive me crazy, I just can’t sleep.
But I am really happy I found this site, and I can’t stop writing, I’m full of ideas.
Thank you, very much.
A:
I'll bite, I have a solution to your problem.
Let us solve the first part of your problem first. The string $a is simply the string that exists between ' and " in your string. And the last part is easy. If you simply do $v = explode(",",$a); your solution to part one will be provided for you. See code example below for what I mean.
$str = "Hi, this is my first attempt at python,
(my own coding skills are limited, no professional programming experience) and
this is a test message to ensure that this website works,
it works.";
$v = explode(",",$str);
foreach ($v as $i => $value) {
$final = $value;
$test = substr($value, 0,4);
if ($test != $final) {
echo "You don't like that!";
} else {
echo "You like that!";
}
}
The above code should do exactly what you want.
You can find the PHP documentation on substr() here
A:
The problem is that " Hi, this is my first attempt at python," and "and " are not included in the word which you intend to delete, so
preg_match('/^\w+(?=[\s"])$/', $str);
Doesn't delete the rest of the sentence.
A:
There are two solutions:
delete everything between ( and ")
deleting the word " my first"
$str = preg_replace('/.*(\(.*?\)).*$/', '', $str);
delete only the first two sentence
$str = preg_replace('/(\s{2}\S*\s+[a-zA-Z\s]{2,}).*$/', '', $str);
\s - space
\s+ - 1 or more whitespace
\S* - not a whitespace
This one deletes only a certain number of spaces and then stops checking.
http://php.net/manual/en/regexp.reference.repetition.php#example-24
Test case here: https://regex101.com/r/fH6kH1/1
However, I would solve the problem this way:
PHP example:
$str = 'Hi, this is my first attempt at python, (my own coding skills are limited, no professional programming experience) and this is a test message to ensure that this website works, it works.';
$str = preg_replace('~[^\S\n]+~', '', $str);
echo nl2br($str);
Console output:
Hi, this is a test message to ensure that this website works, it works.
So you simply remove everything that's not a word or a whitespace.
However, if you want to remove everything between quotes: