regex - Php regexp for escaping characters -


i have string user may split manually using comma's.

for example, string value1,value2,value3 should result in array:

["value1", "value2", "value3"]

now if user wishes allow comma substring? solve problem letting user escape comma using 2 comma's or backslash. example, string

"hi, stackoverflow" written "hi,, stackoverflow" or "hi\, stackoverflow".

i find difficult evaluate such string however. have attempted preg splitting, there no way see if lookbehind or lookahead series of characters consists of or odd number. furthermore, backslashes , double comma's meant escaping must removed well, requires additional replace function.

$text = 'hello, world \,asdas, 123'; $data = preg_split('/(?<=[^\\\]),/',$text); print_r($data); 

result

array ( [0] => hello [1] => world \,asdas [2] => 123 ) 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -