regex get first match code example
Example 1: regex match to first instance
/[^;]*/
# matches every character before the first ;
Example 2: regex find first instace
adding ".*?" To a answer makes it non greedy
running <h2)*?>
on
<h2 style="text-align: center;">heading</h2>
will return <h2 style="text-align: center;">
Example 3: regex first in line
Just use "^" to specify matching a pattern at the beginning of each line.
Example with grep:
grep "^pattern" file.txt