I need a regex to put into an array all the text that starts with R1Y2A3N and ends with R1Y2A3N.....
Example, I have a variable like this:
$variable = 'Hello R1Y2A3Ne2p0YWc6cGFyYW0gbmFtZT12ZW5kb3JOYW1lfQ==R1Y2A3N and you!';
so, R1Y2A3Ne2p0YWc6cGFyYW0gbmFtZT12ZW5kb3JOYW1lfQ==R1Y2A3N should be put into an array....
please help me with this... thanks!
regex help....
Moderator: General Moderators
Re: regex help....
Base 64 encoding is sooo easy to recognize
Code: Select all
$substr = "R1Y2A3N";
$string = "Hello R1Y2A3Ne2p0YWc6cGFyYW0gbmFtZT12ZW5kb3JOYW1lfQ==R1Y2A3N and you!";
// make sure that $substr shows up (at least) twice in $string
if (strpos($string, $substr, strpos($string, $substr) + 1)) {
list($left, $inner, $right) = explode($substr, $string);
echo $substr . $inner . $substr, "<br>\n";
echo base64_decode($inner), "<br>\n";
}Re: regex help....
is preg_match_all possible to do this?
I have this code,
preg_match_all("/(?s)R1Y2A3N(.+?)\R1Y2A3N/", $variable, $matches, PREG_PATTERN_ORDER);
but it would not work properly... i think this needs some modification and I dont know what to modify....
i want it to be in preg_match_all because the matches are stored in an array and i can simply
do a foreach in each matches....
I have this code,
preg_match_all("/(?s)R1Y2A3N(.+?)\R1Y2A3N/", $variable, $matches, PREG_PATTERN_ORDER);
but it would not work properly... i think this needs some modification and I dont know what to modify....
i want it to be in preg_match_all because the matches are stored in an array and i can simply
do a foreach in each matches....
Re: regex help....
Is there going to be more than one match?
Regular expressions are slow. Using normal string functions (if possible) is best.
Regular expressions are slow. Using normal string functions (if possible) is best.
-
BornForCode
- Forum Contributor
- Posts: 147
- Joined: Mon Feb 11, 2008 1:56 am
Re: regex help....
In the case that you have more then a result go for regex.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: regex help....
Remove the backslash from your regex pattern.revbackup wrote:is preg_match_all possible to do this?
I have this code,
preg_match_all("/(?s)R1Y2A3N(.+?)\R1Y2A3N/", $variable, $matches, PREG_PATTERN_ORDER);
but it would not work properly... i think this needs some modification and I dont know what to modify....
i want it to be in preg_match_all because the matches are stored in an array and i can simply
do a foreach in each matches....
And you can remove the PREG_PATTERN_ORDER, by default this option is already chosen.