Search code examples
regexstringstringrstringi

Extract strings between special characters


Please help me in extracting the string from this text like

  1. id1:value1,id2:value2

  2. id1:value1a,id2:value2a

from

"[{id1:value1,id2:value2},{id1:value1a,id2:value2a}]"


Solution

  • Working codes

    unlist(regmatches(text, gregexpr("\\{.*?\\}", text)))

    unlist(regmatches(text, gregexpr("\\{([^}]+)\\}", text)))