Python detect character surrounded by spaces
<p>Anyone know how I can find the character in the center that is surrounded by spaces?</p>

<p><code>1 + 1</code></p>

<p>I'd like to be able to separate the <code>+</code> in the middle to use in a if/else statement.</p>

<p>Sorry if I'm not too clear, I'm a Python beginner.</p>

<p>This regular expression will detect a single character surrounded by spaces, if the character is a plus or minus or mult or div sign: <code>r' ([+-*/]) '</code>. Note the spaces inside the apostrophes. The parentheses "capture" the character in the middle. If you need to recognize a different set of characters, change the set inside the brackets.</p>

<p>If you haven't dealt with regular expressions before, read up on the <code>re</code> module. They are very useful for simple text processing. The two relevant features here are "character classes" (the square brackets in my example) and "capturing parentheses" (the round parens).</p>

python python-3.x