Use RegEx to be "un" greedy

Document created by rich_patterson Employee on Oct 22, 2014Last modified by dave_lesshafft on Mar 1, 2016
Version 2Show Document
  • View in full screen mode
You can use a "?" after an expression, to be "un" greedy.


Example: "hello world hello world"


If you search for "hello.*world" you will get the entire string back.
If you search for "hello.*?world" you will only get one "hello world" back.


If you want to return only the first instance of an XML element, try this:


Search String: "(?s)<element>.*?<\/element>"


This will match only a single instance of element.
1 person found this helpful