python - Regular Expression to use in Split function -


i new regular expressions. can me in regular expression split below data. tried regex \\\\, splitting on comma inside braces , outside also. commas inside braces [] should skipped.

input

[111,212],[231,543],[231,423] 

output

[111,212] [231,543] [231,423] 

if sure there no spaces around commas, split regex want ,(?=\[)

example in javascript:

$ node > re = /,(?=\[)/ /,(?=\[)/ > "[111,212],[231,543],[231,423]".split(re) [ '[111,212]', '[231,543]', '[231,423]' ] 

example in python:

$ python >>> import re >>> r = re.compile(r',(?=\[)') >>> re.split(r, "[111,212],[231,543],[231,423]") ['[111,212]', '[231,543]', '[231,423]'] 

explanation: ,(?=\[) means comma followed left bracket. expression in (?=) positive lookahead , not consumed. thing used splitter comma itself. commas split on ones followed left brackets. don't split on other commas.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -