how to find match first word in string with regex in python
<p>I want to match the word <code>'St' or 'St.' or 'st' or 'st.'</code> BUT only in first word of a string.
For example ' St. Mary Church Church St.' - should find ONLY first St. </p>

<ul>
<li>'st. Mary Church Church St.' - should find ONLY 'st.' </li>
<li>'st Mary Church Church St.' - should find ONLY 'st'</li>
</ul>

<p>I want to eventually replace the first occurence with 'Saint'.</p>

<p>I have literally spent hours trying to find a regex that will match this problem so i have tried myself first and i now for some of you it will be easy!</p>

<p>Try using the regex <code>'^\S+'</code> to match the first non-space character in your string.</p>

<pre><code>import re 

s = 'st Mary Church Church St.'
m = re.match(r'^\S+', s)
m.group()    # 'st'

s = 'st. Mary Church Church St.'
m = re.match(r'^\S+', s)
m.group()    # 'st.'
</code></pre>

python regex