php - Locating a specific string in a column between two strings which are not always there? -


long story short, let's assume have field in column called 'whyisthisalist' 'table' contains:

{example1:"hereistext";example2:"ohlookmoretext";example3:"isthisevenreal"} 

how extract text between example1 , example2, given example2 isn't there because this:

{example1:"hereistext";example7:"ohlookmoretext"} 

it should return "hereistext" if goes well.

my idea far:

$sql = "select substring(left(whyisthisalist, locate('\";', whyisthisalist) +0), locate('example1:\"', whyisthisalist) +0, 100) table locate('\";', whyisthisalist) > 0 , locate('example1:\"', whyisthisalist) > 0 order id desc limit 1"; 

what needs done/doesn't work: need next occuring "; after previous located string. possible? or there other workaround? i'd glad help.

the following regex first colon first semi-colon:

\:([^;]*) 

simplifying query this:

select `whyisthisalist` regexp '\:([^;]*)' `table` 

mysql regex docs
mysql pattern matching

you can use lookahead's , lookbehind's regex:

(?<=example1:)(.+?)(?=\;) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -