regular expressions three solutions present themselves (apart from using proper parserone is ]*(match characters and then the tag' closing character)another is (match <imgthen any number of charactersbut nongreedilyso it will stop immediately before the tag' closing >and then the >)and third combines bothas in ]*?none of them is correctthoughsince they can all match which is not valid since we know that an image tag must have src attributea more accurate regex is ]*?src=\ +[^>]*?this matches the literal characters <imgthen one or more whitespace charactersthen nongreedily zero or more of anything except (to skip any other attributes such as alt)then the src attribute (the literal characters srcthen at least one "wordcharacter)and then any other non-characters (including noneto account for any other attributesand finally the closing grouping and capturing |in practical applications we often need regexes that can match any one of two or more alternativesand we often need to capture the match or some part of the match for further processing alsowe sometimes want quantifier to apply to several expressions all of these can be achieved by grouping with ()and in the case of alternatives using alternation with alternation is especially useful when we want to match any one of several quite different alternatives for examplethe regex aircraft|airplane|jet will match any text that contains "aircraftor "airplaneor "jetthe same thing can be achieved using the regex air(craft|plane)|jet herethe parentheses are used to group expressionsso we have two outer expressionsair(craft|planeand jet the first of these has an inner expressioncraft|planeand because this is preceded by air the first outer expression can match only "aircraftor "airplaneparentheses serve two different purposes--to group expressions and to capture the text that matches an expression we will use the term group to refer to grouped expression whether it captures or notand capture and capture group to refer to captured group if we used the regex (aircraft|airplane|jetit would not only match any of the three expressionsbut would also capture whichever one was matched for later reference compare this with the regex (air(craft|plane)|jetwhich has two captures if the first expression matches ("aircraftor "airplaneas the first capture and "craftor "planeas the second capture)and one capture if the second expression matches ("jet"we can switch off the capturing effect by following an opening parenthesis with ?:so for example(air(?:craft|plane)|jetwill have only one capture if it matches ("aircraftor "airplaneor "jet" grouped expression is an expression and so can be quantified like any other expression the quantity is assumed to be one unless explicitly given for