Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I need to parse string like that :
- # BEGIN STRING
- This is my string...
- [foo-1 param1 : value1, param2 : value2]
- [foo-2 param1 : value1, param2 : value2, params3 : value3]
- # and so on
- # END STRING
- # My purpose here is to get all the sequence between [ ] firstly and then to parse all the params.
- # I wrote 2 regex for that, the first one is supposed to get all the sequence between [] :
- /\[([\w-]+)\s?([\w@.,:\s]*)\]/m
- # My second regex to parse all my parameters
- /([\w]+)\s?,?:\s?,?([\w@.-]+)/m
- # My problem is that I'm always getting the first match but I'd of course like to get all the matches.
- # I tried to do this :
- r = /\[([\w-]+)\s?([\w@.,:\s]*)\]/m
- str = "[foo-1 param1 : value1, param2 : value2]
- [foo-2 param1 : value1, param2 : value2, params3 : value3]"
- m = r.match(str)
- # #<MatchData "[foo-1 param1 : value1, param2 : value2]" 1:"foo-1" 2:"param1 : value1, param2 : value2">
Advertisement
Add Comment
Please, Sign In to add comment