Re: [Tutor] regular expressions query

2019-05-24 Thread Mats Wichmann
On 5/23/19 6:15 PM, mhysnm1...@gmail.com wrote: > All, > > > > Below I am just providing the example of what I want to achieve, not the > original strings that I will be using the regular expression against. > > > > The original strings could have: > > > > "Hello world" > > "hello Wor

Re: [Tutor] regular expressions query

2019-05-24 Thread Alan Gauld via Tutor
On 24/05/2019 01:15, mhysnm1...@gmail.com wrote: > Below I am just providing the example of what I want to achieve, not the > original strings that I will be using the regular expression against. While I'm sure you understand what you want I'm not sure I do. Can you be more precise? > The origin

[Tutor] regular expressions query

2019-05-24 Thread mhysnm1964
All, Below I am just providing the example of what I want to achieve, not the original strings that I will be using the regular expression against. The original strings could have: "Hello world" "hello World everyone" "hello everyone" "hello world and friends" I have a string

Re: [Tutor] Regular expressions

2014-02-15 Thread Santosh Kumar
Thank you all. On Thu, Feb 13, 2014 at 10:47 PM, Walter Prins wrote: > Hi, > > On 13 February 2014 06:44, Santosh Kumar wrote: > > I am using ipython. > > > > 1 ) Defined a string. > > > > In [88]: print string > > foo foobar > > > > 2) compiled the string to grab the "foo" word. > > > > In [8

Re: [Tutor] Regular expressions

2014-02-13 Thread Walter Prins
Hi, On 13 February 2014 06:44, Santosh Kumar wrote: > I am using ipython. > > 1 ) Defined a string. > > In [88]: print string > foo foobar > > 2) compiled the string to grab the "foo" word. > > In [89]: reg = re.compile("foo",re.IGNORECASE) > > 3) Now i am trying to match . > > In [90]: match = r

Re: [Tutor] Regular expressions

2014-02-12 Thread Peter Otten
Santosh Kumar wrote: > Hi all, > > I am using ipython. > > 1 ) Defined a string. > > In [88]: print string > foo foobar > > 2) compiled the string to grab the "foo" word. > > In [89]: reg = re.compile("foo",re.IGNORECASE) > > 3) Now i am trying to match . > > In [90]: match = reg.match(stri

[Tutor] Regular expressions

2014-02-12 Thread Santosh Kumar
Hi all, I am using ipython. 1 ) Defined a string. In [88]: print string foo foobar 2) compiled the string to grab the "foo" word. In [89]: reg = re.compile("foo",re.IGNORECASE) 3) Now i am trying to match . In [90]: match = reg.match(string) 4) Now i print it. In [93]: print match.group()

Re: [Tutor] Regular expressions question

2012-12-06 Thread Mark Lawrence
On 06/12/2012 11:31, Steven D'Aprano wrote: On 06/12/12 20:53, Albert-Jan Roskam wrote: Lately I started using named groups (after I didn't understand some of my own regexes I wrote several months earlier). Months? I can't understand my own regexes about six seconds after I look away from t

Re: [Tutor] Regular expressions question

2012-12-06 Thread Steven D'Aprano
On 06/12/12 20:53, Albert-Jan Roskam wrote: Lately I started using named groups (after I didn't understand some of my own regexes I wrote several months earlier). Months? I can't understand my own regexes about six seconds after I look away from the screen. The downside is that the regexes

Re: [Tutor] Regular expressions question

2012-12-06 Thread Albert-Jan Roskam
___ >From: eryksun >To: Ed Owens >Cc: "tutor@python.org" >Sent: Thursday, December 6, 2012 3:08 AM >Subject: Re: [Tutor] Regular expressions question > >On Wed, Dec 5, 2012 at 7:13 PM, Ed Owens wrote: >>>>> str(string

Re: [Tutor] Regular expressions question

2012-12-05 Thread eryksun
On Wed, Dec 5, 2012 at 7:13 PM, Ed Owens wrote: str(string) > '[\nUpdated: > Dec 5, 2012, 5:08pm EST\n]' m = re.search('":\b(\w+\s+\d+,\s+\d+,\s+\d+:\d+.m\s+\w+)<', str(string)) print m > None You need a raw string for the boundary marker \b (i.e the boundary between \w and \W), el

Re: [Tutor] Regular expressions question

2012-12-05 Thread Brett Ritter
On Wed, Dec 5, 2012 at 5:04 PM, Ed Owens wrote: > >>> m = re.search(':\b(\w+\s+\d+,\s+\d+,\s+\d+:\d+.m\s+\w+)<', str(string)) > >>> print m > None > >>> > Okay, without the double-quote (it wasn't the colon that I was worried about, it was the double-quote), I believe the issue now is that you h

Re: [Tutor] Regular expressions question

2012-12-05 Thread Alan Gauld
On 06/12/12 00:24, Brett Ritter wrote: '[\nUpdated: Dec 5, 2012, 5:08pm EST\n]' >>> m = re.search('":\b(\w+\s+\d+,\s+\__d+,\s+\d+:\d+.m\s+\w+)<', It starts with ": which doesn't appear in your string. At the end of Updated: -- Alan G Author of the Learn to Program web site http://w

Re: [Tutor] Regular expressions question

2012-12-05 Thread Alan Gauld
On 06/12/12 00:13, Ed Owens wrote: >>> str(string) '[\nUpdated: Dec 5, 2012, 5:08pm EST\n]' >>> m = re.search('":\b(\w+\s+\d+,\s+\d+,\s+\d+:\d+.m\s+\w+)<', str(string)) >>> print m None >>> I'm sort of embarrassed to ask this, but I've been staring at this regular expression for hours and ca

Re: [Tutor] Regular expressions question

2012-12-05 Thread Ed Owens
On 12/5/12 7:24 PM, Brett Ritter wrote: On Wed, Dec 5, 2012 at 4:13 PM, Ed Owens > wrote: >>> str(string) '[\nUpdated: Dec 5, 2012, 5:08pm EST\n]' >>> m = re.search('":\b(\w+\s+\d+,\s+\d+,\s+\d+:\d+.m\s+\w+)<', str(string)) >>> print m None I

Re: [Tutor] Regular expressions question

2012-12-05 Thread Brett Ritter
On Wed, Dec 5, 2012 at 4:13 PM, Ed Owens wrote: > >>> str(string) > '[\nUpdated: Dec 5, 2012, 5:08pm EST\n]' > >>> m = re.search('":\b(\w+\s+\d+,\s+\**d+,\s+\d+:\d+.m\s+\w+)<', > str(string)) > >>> print m > None > It starts with ": which doesn't appear in your string. -- Brett Ritter / SwiftO

[Tutor] Regular expressions question

2012-12-05 Thread Ed Owens
>>> str(string) '[\nUpdated: Dec 5, 2012, 5:08pm EST\n]' >>> m = re.search('":\b(\w+\s+\d+,\s+\d+,\s+\d+:\d+.m\s+\w+)<', str(string)) >>> print m None >>> I'm sort of embarrassed to ask this, but I've been staring at this regular expression for hours and can't see why it doesn't work. I'm tr

Re: [Tutor] Regular expressions: findall vs search

2012-07-10 Thread Steven D'Aprano
Alexander Q. wrote: My question is how does Python know to return just the part in the parentheses and not to return the "blahblah" and the "yattayattayatta", etc...? The 're.search' function returns the whole thing, and if I want just the parentheses parts, I do tuples.group(1) or tuples.group(

Re: [Tutor] Regular expressions: findall vs search

2012-07-10 Thread Hugo Arts
On Tue, Jul 10, 2012 at 9:26 PM, Alexander Q. wrote: > I'm a bit confused about extracting data using re.search or re.findall. > > Say I have the following code: tuples = > re.findall(r'blahblah(\d+)yattayattayatta(\w+)moreblahblahblah(\w+)over', > text) > > So I'm looking for that string in 'tex

[Tutor] Regular expressions: findall vs search

2012-07-10 Thread Alexander Q.
I'm a bit confused about extracting data using re.search or re.findall. Say I have the following code: tuples = re.findall(r'blahblah(\d+)yattayattayatta(\w+)moreblahblahblah(\w+)over', text) So I'm looking for that string in 'text', and I intend to extract the parts which have parentheses around

Re: [Tutor] regular expressions

2008-08-05 Thread Kent Johnson
On Tue, Aug 5, 2008 at 7:01 AM, Jim Morcombe <[EMAIL PROTECTED]> wrote: > Could someone please give me some help using the "re" module. > If I have: > text = "Bill Smith is nice" > how do I get rid of "Smith" and just have > "Bill is nice" > > I tried > s2 = re.sub('Smith', '', text) > but it comp

Re: [Tutor] regular expressions

2008-08-05 Thread Monika Jisswel
here is what my interpreter gives : >>> >>> >>> text = "Bill Smith is nice" >>> print text Bill Smith is nice >>> re.sub('Smith', '', text) 'Bill is nice' >>> text = "Jim likes a girl (Susan)" >>> print text Jim likes a girl (Susan) >>> KeyboardInterrupt >>> re.sub('(Susan)', '', text) 'Jim likes

Re: [Tutor] regular expressions

2008-08-05 Thread arsyed
On Tue, Aug 5, 2008 at 7:01 AM, Jim Morcombe <[EMAIL PROTECTED]> wrote: > Could someone please give me some help using the "re" module. > > This works: > > import re > > text = "Jim is a good guy" > > s2 = re.sub('Jim', 'Fred', text) > print s2 > > and I get "Fred i

[Tutor] regular expressions

2008-08-05 Thread Jim Morcombe
Could someone please give me some help using the "re" module. This works: import re text = "Jim is a good guy" s2 = re.sub('Jim', 'Fred', text) print s2 and I get "Fred is a good guy" - If I have: text = "Bill Smith is nice" how

Re: [Tutor] Regular Expressions: escaping in character classes/character sets

2008-07-07 Thread Kent Johnson
On Mon, Jul 7, 2008 at 1:44 AM, Josh Rosen <[EMAIL PROTECTED]> wrote: > I was browsing through the source code of Django when I found the following > regular expression: > > tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]') > > Shouldn't this be > functionally equivalent to the much more readable

[Tutor] Regular Expressions: escaping in character classes/character sets

2008-07-06 Thread Josh Rosen
I was browsing through the source code of Django when I found the following regular expression: tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]') As it turns out, this line from the message module in the Python standard library's email module. It seems to be used to determine if an ema

Re: [Tutor] Regular expressions...

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 1:38 PM, Spencer Parker <[EMAIL PROTECTED]> wrote: > Well...it gives me the entire path...I am not running this script from the > actual directory...I am running it from a secure user directory that only > has certain access rights. During the os.path.dirname gives me the en

Re: [Tutor] Regular expressions...

2008-05-02 Thread jay
dir = '/xen/domains2/machinename/disk.img' a = dir.split('/')[3] is what I would use... On Fri, May 2, 2008 at 12:38 PM, Spencer Parker <[EMAIL PROTECTED]> wrote: > Well...it gives me the entire path...I am not running this script from the > actual directory...I am running it from a secure user

Re: [Tutor] Regular expressions...

2008-05-02 Thread Spencer Parker
Well...it gives me the entire path...I am not running this script from the actual directory...I am running it from a secure user directory that only has certain access rights. During the os.path.dirname gives me the entire directory path...I just need to last part of it is all. out of '/xen/domain

Re: [Tutor] Regular expressions...

2008-05-02 Thread Kent Johnson
On Fri, May 2, 2008 at 12:08 PM, Spencer Parker <[EMAIL PROTECTED]> wrote: > I need to use a regular expression to get a couple of items for my python > script. So far the script is running an 'ls' command to get a few items > that I need > > I run an 'ls -sk /xen/domains2/machinename/disk.img' >

Re: [Tutor] Regular expressions...

2008-05-02 Thread Jerry Hill
On Fri, May 2, 2008 at 12:08 PM, Spencer Parker <[EMAIL PROTECTED]> wrote: > I need to use a regular expression to get a couple of items for my python > script. So far the script is running an 'ls' command to get a few items > that I need Why do you need to use regular expressions? This problem

[Tutor] Regular expressions...

2008-05-02 Thread Spencer Parker
I need to use a regular expression to get a couple of items for my python script. So far the script is running an 'ls' command to get a few items that I need I run an 'ls -sk /xen/domains2/machinename/disk.img' Output 2454112 /xen/domains2/machinename/disk.img Then I have it running an 'ls -lk

Re: [Tutor] Regular expressions - Ignoring linefeeds

2007-03-02 Thread Kent Johnson
Luke Paireepinart wrote: > Kent Johnson wrote: >> Luke Paireepinart wrote: >>> Your RE is wrong. >>> Refer to http://docs.python.org/lib/re-syntax.html >>> * Causes the resulting RE to match 0 or more repetitions of the >>> preceding RE, as many repetitions as are possible. ab* will match >>> 'a'

Re: [Tutor] Regular expressions - Ignoring linefeeds

2007-03-02 Thread Luke Paireepinart
Kent Johnson wrote: > Luke Paireepinart wrote: > >> doug shawhan wrote: >> >>> I've been looking through various sites, but cannot find the magic >>> button that allows me to match a string with linefeeds >>> I'd rather not strip out the linefeeds, then stick them back in. :-) >>> >>> I'm

Re: [Tutor] Regular expressions - Ignoring linefeeds

2007-03-02 Thread Kent Johnson
Luke Paireepinart wrote: > doug shawhan wrote: >> I've been looking through various sites, but cannot find the magic >> button that allows me to match a string with linefeeds >> I'd rather not strip out the linefeeds, then stick them back in. :-) >> >> I'm attempting something that should be fairl

Re: [Tutor] Regular expressions - Ignoring linefeeds

2007-03-02 Thread Kent Johnson
doug shawhan wrote: > I've been looking through various sites, but cannot find the magic > button that allows me to match a string with linefeeds > I'd rather not strip out the linefeeds, then stick them back in. :-) > > I'm attempting something that should be fairly simple: > > snippy = re.comp

Re: [Tutor] Regular expressions - Ignoring linefeeds

2007-03-02 Thread Luke Paireepinart
doug shawhan wrote: > I've been looking through various sites, but cannot find the magic > button that allows me to match a string with linefeeds > I'd rather not strip out the linefeeds, then stick them back in. :-) > > I'm attempting something that should be fairly simple: > > snippy = re.compil

Re: [Tutor] Regular expressions - Ignoring linefeeds

2007-03-02 Thread Jerry Hill
On 3/2/07, doug shawhan <[EMAIL PROTECTED]> wrote: > I've been looking through various sites, but cannot find the magic button > that allows me to match a string with linefeeds > I'd rather not strip out the linefeeds, then stick them back in. :-) Try this: >>> s = '''Good gravy! Hi there. I'm so

[Tutor] Regular expressions - Ignoring linefeeds

2007-03-02 Thread doug shawhan
I've been looking through various sites, but cannot find the magic button that allows me to match a string with linefeeds I'd rather not strip out the linefeeds, then stick them back in. :-) I'm attempting something that should be fairly simple: snippy = re.compile('Hi there.*Bye there.') s = '

Re: [Tutor] regular expressions question]

2006-08-12 Thread nimrodx
Hi Alan and other Gurus, if you look carefully at the string below, you see that in amongst the "\x" stuff you have the text I want: z tfile://home/alpha which I know to be an address on my system, plus a bit of preceeding txt. Alan Gauld wrote: >> The file's encoding is binary or something >> >>

Re: [Tutor] regular expressions question

2006-08-12 Thread Alan Gauld
> The file's encoding is binary or something > > Here is the first section of the file: > '\x00\x00\x00\x02\xb8,\x08\x9f\x00\x00z\xa8\x00\x00\x01\xf4\x00\x00\x01\xf4\x00\x00\x00t\x00f\x00i\x00l\x00e\x00:\x00/\x00h\x00o\x00m\x00e\x00/\x00a\x00l' > > Does that tell you anything? Recall that on a 32

[Tutor] regular expressions question

2006-08-12 Thread nimrodx
Hi All, I am trying to fish through the history file for the Konquerer web browser, and pull out the web sites visited. The file's encoding is binary or something Here is the first section of the file: '\x00\x00\x00\x02\xb8,\x08\x9f\x00\x00z\xa8\x00\x00\x01\xf4\x00\x00\x01\xf4\x00\x00\x00t\x00f

Re: [Tutor] Regular expressions

2006-06-26 Thread Danny Yoo
On Sun, 25 Jun 2006, ravi sankar wrote: >we are doing an intranet portral search.we had a look at the > tutorials for Regular expressions...we need an insight on how to > implement this.we r in the process of developing a unified search... If you have a question, please ask it directly.

[Tutor] Regular expressions

2006-06-24 Thread ravi sankar
hello all we are doing an intranet portral search.we had a look at the tutorials for Regular expressions...we need an insight on how to implement this.we r in the process of developing a unified search...--  regards,   ravi. ___ Tutor maillist - Tu

Re: [Tutor] regular expressions - backslashes

2006-04-06 Thread Kent Johnson
Justin Ezequiel wrote: > will try to convince my colleague to use string formatting > if he insists on regexp then he can do > re.sub(r'(?i)', apppath.replace('\\', ''), template) > > re.escape does not quite work for my example > re.sub(r'(?i)', re.escape(apppath), template) > 'C\\:\\n

Re: [Tutor] regular expressions - backslashes

2006-04-06 Thread Justin Ezequiel
Kent wrote: """The problem is that the re engine itself is interpreting the backslashes in the replacement pattern. With a single slash you get a newline even though the slash is a literal in the replacement string: So if you want a literal \ in your replacement text you have to escape the \, ev

Re: [Tutor] regular expressions - backslashes

2006-04-06 Thread Kent Johnson
Justin Ezequiel wrote: > a colleague demonstrated a problem he had with regular expressions > apppath = os.path.abspath(os.curdir) apppath > 'C:\\napp_and_author_query\\napp_and_author_query\\a b c d' template = r'\files' template > '\\files' re.sub(r'(?i)', apppath, templ

[Tutor] regular expressions - backslashes

2006-04-05 Thread Justin Ezequiel
a colleague demonstrated a problem he had with regular expressions >>> apppath = os.path.abspath(os.curdir) >>> apppath 'C:\\napp_and_author_query\\napp_and_author_query\\a b c d' >>> template = r'\files' >>> template '\\files' >>> re.sub(r'(?i)', apppath, template) 'C:\napp_and_author_query\napp_

Re: [Tutor] regular expressions

2005-12-07 Thread Alan Gauld
> a scientist suggested me to try biopython. This point > is not just with genbank sequences. what will i do if > i have to parse a paragraph for some expression. One thing to watch is that re.match() only checks if the pattern is at the beginning of the line. You should maybe consider using re

Re: [Tutor] regular expressions

2005-12-07 Thread Danny Yoo
On Wed, 7 Dec 2005, ps python wrote: > sorry for repost. awaiting to hear from some members. a scientist > suggested me to try biopython. This point is not just with genbank > sequences. what will i do if i have to parse a paragraph for some > expression. thanks again. Hello, I just want to

Re: [Tutor] regular expressions

2005-12-07 Thread Danny Yoo
On Wed, 7 Dec 2005, ps python wrote: > I am a new python learner. i am trying to parse a file using regular > expressions. Hello, Just as an aside: parsing Genbank flat files like this is not such a good idea, because you can get the Genbank XML files instead. For example, your locus NM_005

Re: [Tutor] regular expressions

2005-12-07 Thread ps python
sorry for repost. awaiting to hear from some members. a scientist suggested me to try biopython. This point is not just with genbank sequences. what will i do if i have to parse a paragraph for some expression. thanks again. hi, I am a new python learner. i am trying to parse a file using

[Tutor] regular expressions

2005-12-07 Thread ps python
hi, I am a new python learner. i am trying to parse a file using regular expressions. LOCUS NM_005417 4145 bpmRNA linear PRI 04-DEC-2005 DEFINITION Homo sapiens v-src sarcoma (Schmidt-Ruppin A-2) viral oncogene homolog (avian) (SRC), transcript variant

Re: [Tutor] regular expressions

2005-07-18 Thread Alan G
> Using regular expressions how do I represent Floats. I'm not certain what you mean by that. Regex searches strings, so the only way floats would be recognised is if you had the string representation of them. Regex won't work with raw floating point data. Assuming you do mean floating point numb

Re: [Tutor] regular expressions

2005-07-17 Thread Danny Yoo
On Sun, 17 Jul 2005, Servando Garcia wrote: > Using regular expressions how do I represent Floats. Hi Servando, I know that you're working on a parser project, but the regex for doing floats is pretty much a homework project. There's not much we can do except point you toward the Regular Expr

[Tutor] regular expressions

2005-07-17 Thread Servando Garcia
Hello Using regular expressions how do I represent Floats. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] regular expressions

2005-07-14 Thread Danny Yoo
> I am working on creating a Domain Specific Language that will > solve partial differential equations. The user will enter a equation in > pseudo code format. [Grammar cut] > It was decided to use Spark for the base for the compiler. To use Spark > all that is need is to just add a new c

Re: [Tutor] regular expressions

2005-07-14 Thread jfouhy
Quoting Servando Garcia <[EMAIL PROTECTED]>: > Hello List > I am working on creating a Domain Specific Language that will solve > partial differential equations. The user will enter a equation in > pseudo code format. I will need to parse the equation. Here is the BNF > for the equation .

[Tutor] regular expressions

2005-07-14 Thread Servando Garcia
Hello List I am working on creating a Domain Specific Language that will solve partial differential equations. The user will enter a equation in pseudo code format. I will need to parse the equation. Here is the BNF for the equation := :=Do :=() :=, | := = :=A() :=() := , | := |