GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Regex perts.. (https://gfy.com/showthread.php?t=1058869)

Jakez 02-24-2012 02:17 PM

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

borked 02-24-2012 02:33 PM

/^([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);

borked 02-24-2012 02:34 PM

or if the pattern occurs ad nauseum

preg_match_all("/([A-Z]+jpg)/", $matches);
var_dump($matches);

Jakez 02-24-2012 02:42 PM

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

margarita 02-24-2012 02:47 PM

([A-Za-z0-9]{4}(?:jpg|jpeg|gif|png)) to remove that jpg, etc. from results

Jakez 02-24-2012 02:50 PM

preg_match_all("/[A-Za-z0-9]{4}(?:jpg|jpeg|gif|png)/","ASDFjpgBLAHjpgQWERjpg",$matches);

perfection! Thanks dudes!!

borked 02-24-2012 02:54 PM

Quote:

Originally Posted by margarita (Post 18779537)
([A-Za-z0-9]{4}(?:jpg|jpeg|gif|png)) to remove that jpg, etc. from results

^^^ what he said for look ahead matching (plus don't listen to me, cos I forgot the $subject :Oh crap )

Code:

preg_match_all("/([A-Za-z0-9]{4}(?:jpg|jpeg|gif|png))/","ASDFjpgBLAHjpgQWERjpg",$matches);

V_RocKs 02-24-2012 06:41 PM

Too late to make an entry for the contest?

Jakez 02-26-2012 12:05 AM

Quote:

Originally Posted by V_RocKs (Post 18779808)
Too late to make an entry for the contest?

Give it your best.

Barry-xlovecam 02-26-2012 06:57 AM

s/jpg/\.jpg/;

HomerSimpson 02-26-2012 09:45 AM

if can you use php

Code:

$x = ""; // that string with all that junk
$a = array(); // resulting array
$x str_replace('jpg', 'jpg|',$x);
$a = explode('|', $x)
var_dump($a);

that should do the trick


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