How can find "<< >>" words from string [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have tried some regex pattern but still can not find some solution for this.
I want get << >> words from following string.
$string = "Yes! Bariatric surgery is covered under your plan. Click <<COMPANY>> here to contact a local surgeon and ask them to confirm your insurance benefits for free. See our <<INSURANCE>> page for coverage criteria or scroll down this page to learn more.";
$dash = substr($string,strpos($string,"<<"),strpos($string,">>"));
If any one knows please help me.
Thanks.

This regular expression will match the words between << and >>
\<{2}([^\>]+)\>{2}
https://regex101.com/r/eX4xI4/1
preg_match_all("/\<{2}([^\>]+)\>{2}/", $string, $matches);
print_r( $matches );
https://eval.in/602428

Related

PHP Unable to do complete regex [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am trying to run
$var = "Guru & Hari - Priya";
if(preg_match('/^[A-Za-z0-9& -]+$/', $var)){
echo "Hi";
}else{
echo "bye";
}
Somehow code is unable to understand "&".
Per regex101.com above code is fine.
Please share why PHP is unable to recogonise &
not-an-answer
You should mention/consider your string source.
What you see as & is probably & in your text value.
The browser rendition is not always an exact representation of your data.
See also: PHP Regex: Matching Ands - & and &

php remove empty single comment [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have code like this
function get_id(){
return 1;
//
}
I want to remove all // inside the source code, but only those stand by it own, on a newline just like the example here. Nothing much nothing more. How can I do it?
Search using this regex:
^\s*\/\/\s*$
and replace by empty string.
If using PHP you can use \h (horizontal space) instead of \s:
$code = preg_replace('~^\h*//\h*$~m', '', $code);

I didn't understand Regex on PHP. [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to clean all special characters from the string with regex code, so far I have did this code
$data = preg_replace('/[^a-zA-Z0-9]/s', '', $nickname);
But this code cleans everything including spaces, I want to allow space and - sign on the string, so what should I exactly add in there? I am sorry if it is an easy question but my English is not really good and I couldn't find any resources in my main language. Could anyone help me with that?
$data = preg_replace('/[^a-zA-Z0-9 -]/s', '', $nickname);
[^a-zA-Z0-9 .-]
Debuggex Demo

Extract a word or number using regular expression [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a string which contain
$mystring = "------------------------
------------------------
<p>
<pre><small>
MessageID=542E7A07, Recipient=1111111111
</small></pre>
------------------------
------------------------";
I would like to get the MessageID and Recipient No. using the regular expression.
MessageID=([a-zA-Z0-9]+)|Recipient=([0-9]+)
You can try this.Grab the matches or captures.See demo.
http://regex101.com/r/sU3fA2/2

How to split a string between two delimiters in php [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I would like to split a string from a whole string which has two delimiters. For example
String1= ABC*WELCOME*CDF
I should get out put as WELCOME.
Note: Delimiters can be any position of the string(not static) but I need only string between those two delimiters
Thanks in advance.
$String1 = 'ABC*WELCOME*CDF';
list( ,$myString, ) = explode('*',$String1);
echo $myString;

Categories