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.
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
How do i assign the successive duplicate values of a string in a single offset of an array In PHP. For example FFF2AA
In array it should be
0=>FFF
1=>2
2=AA
In array format
This post Count consecutive occurence of specific, identical characters in a string - PHP gives you almost your perfect answer. you just have tu use '*' instead of '+' in the regex if you want to take into accounts 1 character strings (like the '2' above).
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 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 have a string for example 'AA231CS'and I want to add a hyphen or dash so it looks like this (the results should be this) 'AA-231-CS'.
and another string '9999ZZZ99' and I want to add a hyphen or dash so it looks like this (the results should be this) '9999-ZZZ-99'.
what's the best approach to handle this?
thank you!
Here is regex required and implode
$string = "9999ZZZ99AAA";
// I have separated string with continous numbers and alphabets in group
preg_match_all('/([0-9]+|[a-zA-Z]+)/',$string,$matches);
// imploding them by `-`
echo implode("-", $matches[0]);
Demo.
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 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)