Match fixed string part 2 [closed] - php

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 have this fixed string below.
edbe801bf92fe7b770f72df2d722df0a
And i match what i need with this regex that someone helped me with and i sort of understand.
(?:[^7]*7){4}([^7]*)
Now i looked at character class use today but i dont know how to include a number to match a string like this except with 5 or 3 in same position as the string with 7
How can i also match these numbers and get my text between the last 5 and 3?
edbe801bf92fe5a250e57eb2d522ef0b
edbe801bf92fe3e532b3f0e2f3e0b5fe
All should be captured
2df2d
7eb2d
f0e2f

If you just want to skip the first twenty character and grab the next five, as your sample suggest, you can do it with this simple regular expresion.
^.{20}(.{5})
This regex give the desired output for all your test lines.

Related

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.

Remove dynamic string from another string PHP (regex) [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 5 years ago.
Improve this question
I need to remove this string
page=x
x being a dynamic string (should be a number but can be anything)
from another string, for example
url/?filter=value&page=2&filter2=value
but it can also be:
url/?page=2
So, these are the cases as examples
1. url/?page=2&filter=value
2. url/?page=2
3. url/?filter=value&page=2
4. url/?filter=value&page=2&filter2=value
And they should return:
1. url/?filter=value
2. url/
3. url/?filter=value
4. url/?filter=value&filter2=value
How can I do that with regex?
You've said:
[?&]page=[^&]+
works for you. This will look for an ? or & then page= and anything after it until an &. A bit longer answer though is:
echo rtrim(preg_replace('/([?&])page=[^&]*&?/', '$1', $string), '&?')
which will correctly handle the intro and ending parameter cases.
Demo: https://3v4l.org/SupbH

REGEX for alternate characters in PHP [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 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

preg match extract digits from string after pattern [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 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+)).

php preg_match() to validate input [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 would like to use the preg_match() to validate a textfield, that clients can later on insert it to the database.
However there is one thing that I don't understand. How would the preg_match() look if I want the client to enter eight numbers and then a dash (-) and four numbers. That input must match exactly
Therefore
N = number
Input:
NNNNNNNN-NNNN
The regex you want is this:
/^\d{8}-\d{4}$/
Demo
This says: match the start of the string (^), exactly 8 digits (\d{8}), a hyphen (-), exactly 4 digits (\d{4}), and then the end of the string ($).
So, the preg_match looks like this:
preg_match('/^\\d{8}-\\d{4}$/', $theData);

Categories