简体   繁体   中英

How to parse this string into tokens using Regular Expression

I would like to parse the following string:

"{Host=pc@ip}{Encoder=EncoderName}{Date=2014_8_5}{Resolution=90X90}
{File=2014-8-5_11-50-50_189.jpeg}"

into five separate strings:

"{Host=pc@ip}"
"{Encoder=EncoderName}"
"{Date=2014_8_5}"
"{Resolution=90X90}"
"{File=2014-8-5_11-50-50_189.jpeg}"

Using a regular expression.

I believe this should work:

\{([^\}]*)\}

Of course, you'll have to worry about a few things, like if you have nested braces, but this works on the string you gave us . I also added in the parentheses, so you should be able to use groups in your matches if you want. It isn't necessary, but I imagine your curly braces will just get in the way of whatever further parsing you do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM