preg match extract digits from string after pattern [closed] - php

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+)).

Related

Match string format with regex [closed]

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$/

Regex to validate the string with comma or space separated [closed]

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 3 years ago.
Improve this question
I am trying to get string through input box from user
user can add only numbers in the string the format of a string is like this
Example
123456,111111,122335
123456 111111 122335
only "," or " " are allowed after 6 digits of number like show in example
You can use
^(?:(?:\d{6},)*|(?:\d{6}\s+)*)\d{6}$
Regex Demo
This regexp is for 3 groups of 6 digits:
\d{6}(?: |,)\d{6}(?: |,)\d{6}
You can test it here.

What is regularexpression to allow specific characters in php [closed]

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);

Regex Replace pattern [closed]

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 8 years ago.
Improve this question
I need the regular expression to replace using following rule:
Any integer present before . then no take place.
If no integer present before . then that should be replace.
$input = (contain anything characters, symbols, numbers, floats etc)
Example:
$myString = "Example 1.58 Stack.68";
Output should be
Example 1.58 Stack,68
preg_replace('#(?<!\d)\.#',',',$myString)

Regex improvement [closed]

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]*?%%/

Categories