Regex - match to obtain words before and after \r\n

Why doesn't my regex match?

SOURCE[\s]*[:]*[\s]*(\r\n|\r|\n)*[\[#x3000\]]*[A-Za-z \!\.\-]*

Text

\xa0SOURCE:\r\nHult International Business School\r\n\r\n\r\n\r\n\r\nSUBJECT: ENTREPRENEURSHIP (92%); 

My regex tries. it seems to work nearly okay here. http://regex101.com/r/aB7nJ2

For some reason, only a [\s] captured the \r\n. i don't understand why. using [\s]* solved it.

Answers


Is your regex pattern defined with a raw string? If so, it should match:

In [25]: import re

In [26]: text = '\xa0SOURCE:\r\nHult International Business School\r\n\r\n\r\n\r\n\r\nSUBJECT: ENTREPRENEURSHIP (92%);'

In [27]: re.search(r'SOURCE[\s]*[:]*[\s]*(\r\n|\r|\n)*[\[#x3000\]]*[A-Za-z \!\.\-]*', text)
Out[27]: <_sre.SRE_Match at 0xb0bffa0>

From the docs:

Raw string notation (r"text") keeps regular expressions sane. Without it, every backslash ('\') in a regular expression would have to be prefixed with another one to escape it.


Missing some escaping?

SOURCE[\s]*[:]*[\s]*(\\r\\n|\\r|\\n)*[\[#x3000\]]*[A-Za-z \!\.\-]*

Need Your Help

Unknown provider: $angularFileUploadProvider <- $angularFileUpload in jasmine angular test

angularjs jasmine karma-jasmine

I have a directive on my angular module that I'm trying to write a test for. First off, I'm not clear how to even test this directive properly, but at this point, I'm getting the following error w...

How can I join tables in Zend while using a class that inherits from Zend_Db_Table_Row_Abstract?

php mysql zend-framework zend-db zend-db-table

I have a class that extends Zend_Db_Table lets call it 'Users' that uses the class 'User' (inheriting from Zend_Db_Table_Row_Abstract) as its rowClass. I need it this way because User has additional