[BangPypers] Parse multi line with re module.

Pratap Chakravarthy prataprc at gmail.com
Tue Jan 3 15:33:23 CET 2012


Hi Ganesh, may be you can try this out,

> re.findall(r'Searching for OPUSH on([^\.\n\r]+)|Channel:([^\r\n]*)', str )
[(' 00:1D:FD:06:99:99 ', ''), ('', ' 9')]

where str contains the string you want to parse. And the regex
contains two groups, defined between (...), suggesting findall() to
search for them. You can learn more about findall() here
http://docs.python.org/library/re.html#finding-all-adverbs

Cheers,

On Tue, Jan 3, 2012 at 7:23 PM, Ganesh Kumar <bugcy013 at gmail.com> wrote:
> Hi Guys,
>
> I want parse multiple line. with re.module, this is my given string
> http://dpaste.com/680760/ I have try with re.compile module. I want parse
> two line mac address and channel,
> I have done with for mac address finding
>
> r = re.compile("^Searching for OPUSH on (\w\w(:\w\w)+)")
>
> for channel finding
>
> device_r = re.compile("^Channel: (\d+)")
>
> the two parsing string working. but I want combine two pattern in to one.
>
> This is my code
> http://www.bpaste.net/show/21323/
>
> please guide me.
>
>
> -Ganesh
>
> Did I learn something today? If not, I wasted it.
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers



-- 
Pratap.


More information about the BangPypers mailing list