Guest User

Untitled

a guest
Jul 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. {"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}
  2.  
  3. <?php
  4. $input = '{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}';
  5. print_r(json_decode($input, true));
  6. ?>
  7.  
  8. Array
  9. (
  10. [chg] => -0.71
  11. [vol] => 40700
  12. [time] => 11.08.2011 12:29:09
  13. [high] => 1.417
  14. [low] => 1.360
  15. [last] => 1.400
  16. [pcl] => 1.410
  17. [turnover] => 56,560.25
  18. )
  19.  
  20. :"([^"].*?)"
  21.  
  22. /:"([^"].*?)"/
  23.  
  24. import java.util.regex.*;
  25.  
  26. String test='{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}'
  27.  
  28. // Create a pattern to match breaks
  29. Pattern p = Pattern.compile(':"([^"]*)"');
  30. // Split input with the pattern
  31. // Run some matches
  32. Matcher m = p.matcher(test);
  33. while (m.find())
  34. System.out.println("Found comment: "+m.group().replace('"','').replace(":",""));
  35.  
  36. Found comment: -0.71
  37. Found comment: 40700
  38. Found comment: 11.08.2011 12:29:09
  39. Found comment: 1.417
  40. Found comment: 1.360
  41. Found comment: 1.400
  42. Found comment: 1.410
  43. Found comment: 56,560.25
  44.  
  45. <?php
  46. $subject = '{"chg":"-0.71","vol":"40700","time":"11.08.2011 12:29:09","high":"1.417","low":"1.360","last":"1.400","pcl":"1.410","turnover":"56,560.25"}';
  47. $pattern = '/(?<=:")[^"]*/';
  48. preg_match_all($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
  49. print_r($matches);
  50. ?>
  51.  
  52. Array ( [0] => Array ( [0] => Array ( [0] => -0.71 [1] => 8 ) [1] => Array ( [0] => 40700 [1] => 22 ) [2] => Array ( [0] => 11.08.2011 12:29:09 [1] => 37 ) [3] => Array ( [0] => 1.417 [1] => 66 ) [4] => Array ( [0] => 1.360 [1] => 80 ) [5] => Array ( [0] => 1.400 [1] => 95 ) [6] => Array ( [0] => 1.410 [1] => 109 ) [7] => Array ( [0] => 56,560.25 [1] => 128 ) ) )
Add Comment
Please, Sign In to add comment