3

I am new to regex. I wish to write a regex which matches a '.' followed by a whitespace followed by a word(which does not contain whitespace.

For example, in the string "The sound of cracking. Splintering. A shape appears, in ice.", the regex should extract ". Splintering" and ". A".

piggs_boson
  • 987
  • 2
  • 12
  • 25
  • 5
    & what have you tried so far to fulfill your wish? – Alok Mar 07 '14 at 10:21
  • Welcome to Stack Overflow. Please take a [tour](http://stackoverflow.com/tour) and visit the [help center](http://stackoverflow.com/help) in order to find information about how to ask a good question. – devnull Mar 07 '14 at 10:25

2 Answers2

9
import re
input = 'The sound of cracking. Splintering. A shape appears, in ice.'
print re.findall("(\.\s+[a-zA-Z]+)", input)

Output: ['. Splintering', '. A']

Múna
  • 312
  • 3
  • 11
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
2

Try:

(\.\s\w+)

Matches:

. Splintering

. A

See it in action.

Community
  • 1
  • 1
e h
  • 8,435
  • 7
  • 40
  • 58