Regex non greedy

  • It can be done using ? at the end of the expression.
  • It matches as few as possible
  • .* is greedy while .*? isn’t
  • take the following string
  • "hash":"sDr3qD6Hu48t1XT3AEk2A/W8n0+fXy5Pckr1ANtY3/c=","objectType":"Applications.GlobalCategoryViewState",
  • the regex "hash":".*", matches the whole string
  • making it non greedy "hash":".*?", matches till the first comma after the hash attribute.