![]() |
Regex perts..
Can anyone help with this simple regex really quick, the shit always mind fucks me.
I need to split this: ASDFjpgQWERjpg into: [0] => ASDFjpg [1] => QWERjpg Can split it with 'jpg' but don't know how to keep the jpg on the end of them. Please save me from this hour long headache :1orglaugh |
/^([A-Z]+jpg)([A-Z]+jpg)$/
or if you're wanting php preg_match: preg_match("/^([A-Z]+jpg)([A-Z]+jpg)$/", $matches); var_dump($matches); |
or if the pattern occurs ad nauseum
preg_match_all("/([A-Z]+jpg)/", $matches); var_dump($matches); |
Should have mentioned there might be a long list of them and not just 2.
This is the best I could do and it works but it's messy and returns too much other shit preg_match_all("/([A-Za-z0-9]{4}(jpg|jpeg|gif|png))/","ASDFjpgBLAHjpgQWERjpg",$matches); Edit: ok this is better but still returning a bunch of "jpg" on the end. preg_match_all("/[A-Za-z0-9]{4}(jpg|jpeg|gif|png)/","ASDFjpgBLAHjpgQWERjpg",$matches); |
([A-Za-z0-9]{4}(?:jpg|jpeg|gif|png)) to remove that jpg, etc. from results
|
preg_match_all("/[A-Za-z0-9]{4}(?:jpg|jpeg|gif|png)/","ASDFjpgBLAHjpgQWERjpg",$matches);
perfection! Thanks dudes!! |
Quote:
Code:
preg_match_all("/([A-Za-z0-9]{4}(?:jpg|jpeg|gif|png))/","ASDFjpgBLAHjpgQWERjpg",$matches); |
Too late to make an entry for the contest?
|
Quote:
|
s/jpg/\.jpg/;
|
if can you use php
Code:
$x = ""; // that string with all that junk |
All times are GMT -7. The time now is 04:47 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123