Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have the following regex:
/%%[\s\S]*?%%/i
It's meant to catch these types of strings:
%%test%%
%%test2%%
However, because this regex runs on big strings, sometimes there are mistakes, for example if i have this:
%test%% adhja kshdjah skdja %%test1%% it will return %% adhja kshdjah skdja %%
The strings that it is supposed to catch never have any spaces in them, how can I alter my regex to take only the ones with no spaces?
Use [^%\s] for non space and non %.
/%%[^%\s]*?%%/
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I know there are tons of questions about regex string format, but I am very new to this and I haven't been able to do it myself. How can I use regex to match a string with the following format?
xx_x_a.zip
where x is a number and a is a letter. Example:
33_2_f.zip
It must not match:
33_2_f_abc.zip
The format must always be like 2digits+_+1digit+_+1letter+.zip
Simplest way:
/^[0-9]{2}_[0-9]_[a-z]\.zip$/
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a string mystring. I have to replace the alternate characters with x so that final output is mxsxrxnx. All the alternate characters starting from 2nd position are replaced with x. I can do it with loop but is there a Regular expression for that or a better way in PHP? Please help.
Using a reset match meta-character \K you are able to do it:
.\K.
Live demo
PHP:
echo preg_replace('/.\K./', 'x', 'mystring'); // mxsxrxnx
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a string of the form
<something>_string_t_<digits>
How can I extract just the <digits> portion in PHP ? I need to detect the string_t first and then pull out the digits.
You want something like this:
$captures;
preg_match('/string_t_(\d+)/', $string, $captures);
do_something($captures[1]);
$captures[1] will contain <digits> (assuming <digits> is composed entirely of numbers - if it's not, use the more general (.+) in place of (\d+)).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i want to allow only characters X,N,-,(Space) to string which user inputs.
Ex : XXXX-NNNNN XXXXXX-NNNN is valid string but
Ex XXXx-1NNN XXXX-NNNN is not valid string.
I have found so many regexp for that but didn't find helpful solution
I want this solution in zend form
Try this:
preg_match("/^[XN -]+$/", $string);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need a pattern which is able to find a word wrapped in two signal characters.
Basically something like
$string = "bablabla __test__ blablabla"
preg_match("/__\w__/", $string, $result);
print_r($result);
\w is a single word character. It would match __t__ but not multiple characters like __test__. Try \w+