newbtophp Posted November 9, 2009 Share Posted November 9, 2009 Im trying to create a preg_match to match variables, which are always 38 characters long and always start with $SPLPF followed by random letters and numbers all uppercase. Example variables: $SPLPFMA7E07CE476A248553FE6D996A078C08 $SPLPFF3ACA209490CBA3B3F38DC9C1DA910TC All help is greatly apreciated :-\ Link to comment https://forums.phpfreaks.com/topic/180899-solved-preg_match-variables-of-a-certain-pattern/ Share on other sites More sharing options...
newbtophp Posted November 9, 2009 Author Share Posted November 9, 2009 Heres my attempt but it doesnt seem to work: /\$SPLPF[A-Z0-9^\d{38,38}$]*/ Link to comment https://forums.phpfreaks.com/topic/180899-solved-preg_match-variables-of-a-certain-pattern/#findComment-954328 Share on other sites More sharing options...
Mchl Posted November 9, 2009 Share Posted November 9, 2009 #^\$SPLPF[A-Z0-9]{32}$# Link to comment https://forums.phpfreaks.com/topic/180899-solved-preg_match-variables-of-a-certain-pattern/#findComment-954330 Share on other sites More sharing options...
newbtophp Posted November 9, 2009 Author Share Posted November 9, 2009 #^\$SPLPF[A-Z0-9]{32}$# Did you mean? #^\$SPLPF[A-Z0-9]{38}$# and how would i intgrate that within a preg_match: for example preg_match('/testing.*#^\$SPLPF[A-Z0-9]{38}$#/'); ? Link to comment https://forums.phpfreaks.com/topic/180899-solved-preg_match-variables-of-a-certain-pattern/#findComment-954341 Share on other sites More sharing options...
Mchl Posted November 9, 2009 Share Posted November 9, 2009 No. I meant 32. Your patter needs to match $SPLPF and then 32 numbers or letters uppercase. As to your other question... what are you trying to do? Link to comment https://forums.phpfreaks.com/topic/180899-solved-preg_match-variables-of-a-certain-pattern/#findComment-954346 Share on other sites More sharing options...
newbtophp Posted November 9, 2009 Author Share Posted November 9, 2009 I meant how would i integrate that variable regex to another regex pattern: like: '/echo\("hey"\);.*^\$SPLPF[A-Z0-9]{32}$/'; would placing the variable like that work? also. if(preg_match('#^\$SPLPF[A-Z0-9]{32}$#', $file)) { echo "match"; } Only seems to work if $file contains just the variable and no other code, is their any modifiers i can add to the regex pattern, so it matches even if theirs more code surrounding that variable. Link to comment https://forums.phpfreaks.com/topic/180899-solved-preg_match-variables-of-a-certain-pattern/#findComment-954375 Share on other sites More sharing options...
Mchl Posted November 9, 2009 Share Posted November 9, 2009 ^ means 'start of line' and $ means 'end of line', so if you need to match these variables anywhere in the line you have to remove these: #\$SPLPF[A-Z0-9]{32}# So joining it with the rest of your pattern: #echo\("hey"\);[^$]*\$SPLPF[A-Z0-9]{32}# Link to comment https://forums.phpfreaks.com/topic/180899-solved-preg_match-variables-of-a-certain-pattern/#findComment-954383 Share on other sites More sharing options...
newbtophp Posted November 9, 2009 Author Share Posted November 9, 2009 thanks that worked perfect! Link to comment https://forums.phpfreaks.com/topic/180899-solved-preg_match-variables-of-a-certain-pattern/#findComment-954409 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.