Uhmm, every time you get an answer, you conjure a new field out of your hat ;-). As to the general answer your're asking for, I'm afraid there might not be such a all-in-one solution. Because each regex pattern is supposed to meet a certain string constellation. But the my last pattern proposal, modified after you added the 'category field', might give you an idea on how to adjust your pattern to subsequently added fields.
string pattern = "(?<=\\[)('\\d+'),(\\d{0,1}),('\\w+\\s?\\w+'),('\\$\\d+')(?=\\])";
For each additional field, you need to insert a new pattern grouping construct, separated from the other groups by a ',' character in accordance to your string example. I think, you' ll see the general pattern.
For your newly added 'description' field, you would add another regex group as below:
string pattern = "(?<=\\[)('\\d+'),(\\d{0,1}),('.+?'),('\\$\\d+'),('.+?')(?=\\])";
One problem hereby is, that I really don't know what your 'Product' and 'Description' field contents look like, but I suppose they are usually not prefixed with "Product ..." or "Description ...", so I used as pattern the most general character class '.'.
Applying this pattern to the following test string:
string text = "<script type=\"text/javascript\">var d=[];d=[['123',1,'Product A','$230','Description A'],['125',,'Product B','$30','Description B'],['126',3,'Product C','$50','Description C']];show(d);</script>";
I got the following result:
Hope it helps,
wizend
No comments:
Post a Comment