Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello sir i have to access all string which is come after "text":

i have to extract- "SAP Remote Basis Support @ $2.29\/hour\/per server. 24x7x365 Support. http:\/\/t.co\/oFuPepEB8c" this statement occur "text" attribute

from

[{"created_at":"Tue Aug 27 21:18:38 +0000 2013","id":372468218289340416,"id_str":"372468218289340416","text":"SAP Remote Basis Support @ $2.29\/hour\/per server. 24x7x365 Support. http:\/\/t.co\/oFuPepEB8c","source":"\u003ca href=\"http:\/\/www.tweetdeck.com\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e"]



please help me with regular expression or other method
Posted
Updated 28-Aug-13 21:26pm
v2
Comments
David Goebet 29-Aug-13 3:27am    
if its always the same syntax (the same string parts like "SAP" and ,"source"
make a substring from the startpoint("SAP") to the (,"source") Endpoint

1 solution

Try this:
C#
string result = Regex.Match(input, "\"text\":\"(?<txt>[^,\"]+)\"").Groups["txt"].Value;

If you have more than one text variable in your input, try this:
C#
string[] results = Regex.Matches(input, "\"text\":\"(?<txt>[^,\"]+)\"").Cast<Match>().Select(x => x.Groups["txt"].Value).ToArray();

Hope this helps.
 
Share this answer
 
v4
Comments
anshu77 29-Aug-13 3:53am    
thank you
there is no error but i can not get correct answer.

actuly i have to get all text data in a file
like-- "text": "hello", "Tue Aug 27 21:18:38 +0000 2013","id":372468218289340416,"id_str":"372468218289340416","text":"SAP Remote Basis Support @ $2.29\/hour\/per server. 24x7x365 Support. http:\/\/t.co\/oFuPepEB8c","source":"\u003ca href=\"http:\/\/www.tweetdeck.com\"

here two time "text" occur so i have 2 access answer-- "hello' and "SAP Remote Basis Support @ $2.29\/hour\/per server. 24x7x365 Support. http:\/\/t.co\/oFuPepEB8c"


thank you in advance
Thomas Daniels 29-Aug-13 4:01am    
I updated my answer.
anshu77 29-Aug-13 4:01am    
i have to access only that text which is occour only after "text": attribute which is end by comma(,) my file data is ----

[{"created_at":"Tue Aug 27 21:18:38 +0000 2013","id":372468218289340416,"id_str":"372468218289340416","text":"SAP Remote Basis Support @ $2.29\/hour\/per server. 24x7x365 Support. http:\/\/t.co\/oFuPepEB8c","source":"\u003ca href=\"http:\/\/www.tweetdeck.com\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":58554692,"id_str":"58554692"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"symbols":[],"urls":[{"url":"http:\/\/t.co\/oFuPepEB8c","expanded_url":"http:\/\/bit.ly\/143rFQs","display_url":"bit.ly\/143rFQs","indices":[68,90]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"created_at":"Tue Aug 27 19:21:25 +0000 2013","id":372438721015988224,"id_str":"372438721015988224","text":"#WFTCloud caters to clients across industries and geographies. View the pic attached to know some of our clients. http:\/\/t.co\/W4mdialBc3","source":"\u003ca href=\"http:\/\/www.tweetdeck.com\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":58554692,"id_str":"58554692"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"WFTCloud","indices":[0,9]}],"symbols":[],"urls":[],"user_mentions":[],"media":[{"id":372438721024376832,"id_str":"372438721024376832","indices":[114,136],"media_url":"http:\/\/pbs.twimg.com\/media\/BSsrCyNCQAAMa3f.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BSsrCyNCQAAMa3f.jpg","url":"http:\/\/t.co\/W4mdialBc3","display_url":"pic.twitter.com\/W4mdialBc3","expanded_url":"http:\/\/twitter.com\/wftus\/status\/372438721015988224\/photo\/1","type":"photo","sizes":{"large":{"w":800,"h":700,"resize":"fit"},"medium":{"w":600,"h":525,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"small":{"w":340,"h":298,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"created_at":"Tue Aug 27 19:18:11 +0000 2013","id":372437908432490496,"id_str":"372437908432490496","text":"SAP on-premise to #Cloud: The journey gets smoother. View pic to know how... http:\/\/t.co\/XpCjgTsMDk","source":"\u003ca href=\"http:\/\/www.tweetdeck.com\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":58554692,"id_str":"58554692"},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"Cloud","indices":[18,24]}],"symbols":[],"urls":[],"user_mentions":[],"media":[{"id":372437908440879104,"id_str":"372437908440879104","indices":[77,99],"media_url":"http:\/\/pbs.twimg.com\/media\/BSsqTfGCEAADKlq.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BSsqTfGCEAADKlq.jpg","url":"http:\/\/t.co\/XpCjgTsMDk","display_url":"pic.twitter.com\/XpCjgTsMDk","expanded_url":"http:\/\/twitter.com\/wftus\/status\/372437908432490496\/photo\/1"}]
Thomas Daniels 29-Aug-13 4:04am    
And what exact text do you want to get from the file?
anshu77 29-Aug-13 4:15am    
thank you vary much
last query worked

thank you

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