Regex return string between two matches [duplicate] - php

This question already has answers here:
Get string between two strings
(6 answers)
Closed 6 years ago.
I'm trying to get the string between two specific matches, for example two hashtags.
What I would like to achieve:
input: some text in front ##hi there## some text behind
output: hi there
With /%%(.*)%%/, ##hi there## is returned.
Thanks in advance

You need a look ahead and look behind.
(?<=##).*(?=##)
This will match hi there
https://regex101.com/r/qUR4NR/1

Related

add INT with STRING in PHP [duplicate]

This question already has answers here:
Getting a number when it has certain prefix from a block of text in PHP
(3 answers)
Zero-pad digits in string
(5 answers)
Closed 1 year ago.
I am trying to add the int with strings in PHP but I could get a helpful answer on StackOverflow and other website communities.
I want the code separate the ALPHABETS and NUMBER and then add the value in NUMBER and again JOIN the ALPHABETS AND ADDED NUMBER together.
How I achieve this, Please help.
Example:
$mynumber = 'SBI0001';
$addValue = '1';
It will be 'SBI0002' in PHP.

Convert string expression in operation in php [duplicate]

This question already has answers here:
calculate math expression from a string using eval
(10 answers)
Closed 4 years ago.
If i've a string like this
((((((4,50*0,86)*52500*1,0016)+3800)/52500)*2,2046)*1,05)
how can i do the operation for obtaning the total result?
Thank You
Maybe your question is a possible duplicate from calculate-math-expression-from-a-string-using-eval
However
if you need to store this in a variable you can do
$string='((((((4,50*0,86)*52500*1,0016)+3800)/52500)*2,2046)*1,05)';
$response=eval('return '.str_replace(',','.',$string.';'));
print($response);
the output is:
9.14027512736

Remove everything before 3rd occurance in PHP [duplicate]

This question already has answers here:
Question about strpos: how to get 2nd occurrence of a string?
(15 answers)
Closed 8 years ago.
i haves string such as
andy
**jackie**
rudy
linda
ferry
**jackie**
linda
rudy
ammy
**jackie**
tortia
Is it possible to have it removed everything and get the result only below
**jackie**
tortia
it should be possible with substr
thanks
Yes, you can use substr.
But at first you have to find third occurence of jackie. Maybe this function will be helpful https://stackoverflow.com/a/18589825/2701717

How to select a word after a # using preg_match in php [duplicate]

This question already has answers here:
Preg replace to words with hash
(3 answers)
Closed 9 years ago.
I want to select a word that as hash using preg_match in php.
For Example consider this string:
Facebook has re-designed #timeline and it is out in New Zealand
Now I want to select #timeline how to do that, I use this code but it select only #t
preg_match_all("/#[a-zA-Z0-9]/")
Thanks in advance :)
It's currently only set up to select a single character following the #. Try this:
preg_match_all("/#[a-zA-Z0-9]+/")

How do I format a variable with commas after every 3 numbers? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to reformat a number with commas
Formatting numbers with thousands separator Smarty PHP
Format a number with grouped thousands
For example the following code:-
{php}echo $youtube->_views;{/php}
returns 2556789 and I want it formatted like this; 2,556,789
This topic says how to do it:
{$myvar|number_format:2:".":","}

Categories