Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
extract strings from a string

string = '[ {"roll" : context("345") }, {"roll" : context("344")) } ]'

Expected output,
['roll', context("345"), 'roll', context("345")]

What I have tried:

Python
import re
re.findall(r'"([^"]*)"', string)
Present Output, ['roll', '345', 'roll', '344']

Expected output,  
['roll', context("345"), 'roll', context("345")]
Posted
Updated 28-Nov-16 22:09pm
v3
Comments
PIEBALDconsult 28-Nov-16 20:33pm    
Unclear. That's what you asked for.
I recommend you get something like Expresso to develop and test your Regular Expressions.

Try
context\("\d*"\)|roll
 
Share this answer
 
Something like:
Python
>>> string = '[ {"roll" : context("345") }, {"roll" : context("344")) } ]'
>>> string2 = string.replace('{','')
>>> string3 = string2.replace('}','')
>>> string4 = string3.replace(':',',')
>>> string4
'[ "roll" , context("345") , "roll" , context("344"))  ]'
>>> 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900