0

I need to filter out the following things from a list:

^[^\w ]$

'^\n( )*$' (\n at the beginning followed by spaces)

'^\n( )*\n$' (\n at both ends with spaces)

'^[]$' (space alone)

how can I combine them into a single expression?

2
  • can you add possible output? Commented Jun 22, 2019 at 13:47
  • use or operator |. plus, space alone is simply ^ $. Make sure you don't mean ^\s$ which is any whitespace character Commented Jun 22, 2019 at 13:50

1 Answer 1

1

try this :

r1 ='^[^\w ]'
r2 ='^\n( )*'
r3= '^\n( )*\n'
r4 = '^\n( )*\n'
string="(\n at the beginning followed by spaces)"
generic_re = re.compile("(%s|%s|%s|%s)" % (r1, r2, r3, r4)).findall(string)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.