On Tuesday, 27 May 2014 16:39:19 UTC+5:30, Vlastimil Brom  wrote:
> 2014-05-27 12:59 GMT+02:00 Aman Kashyap <amankashyap1...@gmail.com>:
> 
> > I would like to create a regular expression in which i can match the "|" 
> > special character too.
> 
> >
> 
> > e.g.
> 
> >
> 
> > start=|ID=ter54rt543d|SID=ter54rt543d|end=|
> 
> >
> 
> > I want to only |ID=ter54rt543d| from the above string but i am unable to 
> > write the  pattern match containing "|" pipe too.
> 
> >
> 
> > By default python treat "|" as an OR operator.
> 
> >
> 
> > But in my case I want to use to as a part of search string.
> 
> > --
> 
> 
> 
> Hi,
> 
> 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.
> 
> 
> 
> hth,
> 
>    vbr


Thanks vbr for the quick response.

I have string = |SOH=|ID=re65dgt5dd|DS=fjkjf|SDID=fhkhkf|ID=fkjfkf|EOM=|

and want to replace 2 sub-strings
|ID=re65dgt5dd| with |ID=MAN|
|ID=fkjfkf| with |MAN|

I am using regular expression ID=[a-z]*[0-9]*[a-z]*[0-9]*[a-z]*|$

the output is |SOH=|ID=MAN|DS=fjkjf|SDID=MAN|ID=MAN|EOM=|ID=MAN

expected value is = |SOH=|ID=MAN|DS=fjkjf|SDID=fhkhkf|ID=MAN|EOM=|

could you please help me in this regard?
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to