exampleif we have read text file with lines of the form key=valuewhere each key is alphanumericthe regex (\ +)=+will match every line that has nonempty key and nonempty value (recall that matches anything except newlines and for every line that matchestwo captures are madethe first being the key and the second being the value for examplethe key=value regular expression will match the entire line topicphysical geography with the two captures shown shaded notice that the second capture includes some whitespaceand that whitespace before the is not accepted we could refine the regex to be more flexible in accepting whitespaceand to strip off unwanted whitespace using somewhat longer version\ ]*(\ +)\ ]*=\ ]*+this matches the same line as before and also lines that have whitespace around the signbut with the first capture having no leading or trailing whitespaceand the second capture having no leading whitespace for exampletopic physical geography we have been careful to keep the whitespace matching parts outside the capturing parenthesesand to allow for lines that have no whitespace at all we did not use \ to match whitespace because that matches newlines (\nwhich could lead to incorrect matches that span lines ( if the re multiline flag is usedand for the value we did not use \ to match nonwhitespace because we want to allow for values that contain whitespace ( english sentencesto avoid the second capture having trailing whitespace we would need more sophisticated regexwe will see this in the next subsection captures can be referred to using backreferencesthat isby referring back to an earlier capture group one syntax for backreferences inside regexes themselves is \ where is the capture number captures are numbered starting from one and increasing by one going from left to right as each new (capturingleft parenthesis is encountered for exampleto simplistically match duplicated words we can use the regex (\ +)\ +\ which matches "word"then at least one whitespaceand then the same word as was captured (capture number is created automatically without the need for parenthesesit holds the entire matchthat iswhat we show underlined we will see more sophisticated way to match duplicate words later in long or complicated regexes it is often more convenient to use names rather than numbers for captures this can also make maintenance easier since adding or removing capturing parentheses may change the numbers but won' affect names to name capture we follow the opening parenthesis with ? for example(? \ +)=(? +has two captures called "keyand "valuethe syntax for backreferences to named captures inside note that backreferences cannot be used inside character classesthat isinside [regex flags