Regular Expression for the special character "|" pipe

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Tue May 27 07:55:58 EDT 2014


On 27.05.2014 13:39, Aman Kashyap wrote:
>> On 27.05.2014 14:09, Vlastimil Brom wrote:
>>
>>> you can just escpape the pipe with backlash like any other metacharacter:
>>>
>>> r"start=\|ID=ter54rt543d"
>>>
>>> be sure to use the raw string notation r"...", or you can double all
>>
>>> backslashes in the string.
>>
> Thanks for the response.
>
> I got the answer finally.
>
> This is the regular expression to be used:\\|ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*\\|
>

or, and more readable:

r'\|ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*\|'

This is what Vlastimil was talking about. It saves you from having to 
escape the backslashes.




More information about the Python-list mailing list