please give me regex ?

A forum for general discussion of the Python programming language.

please give me regex ?

Postby vijaykumbhani » Thu Sep 12, 2013 10:05 am

name ( ( test == test ) and ( test == test ) )

how to match color bracket between content '
how to match first and last bracket?
please give me regex
ex :
output : ( test == test ) and ( test == test )
[b][i]With Regards,
Vijay Kumbhani[/i][/b]
vijaykumbhani
 
Posts: 33
Joined: Wed Aug 14, 2013 4:26 am
Location: Surat, Gujarat, India

Re: please give me regex ?

Postby metulburr » Thu Sep 12, 2013 10:16 am

output : ( test == test ) and ( test == test )


Code: Select all
import re

w = "name ( ( test == test ) and ( test == test ) )"

# find outer parens
outer = re.compile("\((.+)\)")
m = outer.search(w)
inner_str = m.group(1)

print(inner_str)


I am horrible with regex's. I would of used any other method possible. But since you asked for a regex.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: please give me regex ?

Postby Mekire » Thu Sep 12, 2013 11:24 am

Are you seriously trying to say you have made zero progress on this in the past month. You also haven't learned how to ask a question, or how to follow advice or do research.

http://python-forum.org/viewtopic.php?f=10&t=5883&p=7486#p7486

Sigh,
-Mek
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: please give me regex ?

Postby vijaykumbhani » Thu Sep 12, 2013 11:40 am

I found solution:
Code: Select all
pattern = r '(?is) name\s* \((.*)\)(?is)'
data = ' name ( ( test == test ) and ( test == test ) )'

matchObj = re.match(pattern, data)

if matchObj:
        print matchObj.group(1)

Output is :
Code: Select all
( test == test ) and ( test == test )
Last edited by Mekire on Thu Sep 12, 2013 12:30 pm, edited 1 time in total.
Reason: Code tags; NOT colors.
[b][i]With Regards,
Vijay Kumbhani[/i][/b]
vijaykumbhani
 
Posts: 33
Joined: Wed Aug 14, 2013 4:26 am
Location: Surat, Gujarat, India


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest