Re: Regex Group case change

2020-10-01 Thread Cameron Simpson
It is good to see a nice small piece of code which we can run. Thank you. So there are a number of things to comment about in the code below; comments inline under the relevant piece of code (we prefer the "inline reply" style here, it reads like a conversation): On 01Oct2020 15:15, Raju wrot

Re: Regex Group case change

2020-10-01 Thread Raju
import re import os import sys #word = "7 the world" # 7 The world #word = "Brian'S" # Brian's #word = "O'biran"# O'Brian #word = "Stoke-On-Trent" # Stoke-on-Trent; here i need to lower the case of middle word(i.e -On-) def wordpattern(word): output = '' if re.match("^\d+|w*$",word):

Re: Regex Group case change

2020-10-01 Thread Cameron Simpson
On 01Oct2020 12:41, Raju wrote: >I want to change the case on input string i was able to match using >python regex but couldn't find the way to change the case. > >For example string: >Input: 7Section Hello Jim >output: 7Section hello Jim > >I was doing if statment with regex > >if re.match("(\d+

Re: Regex to change multiple lines

2020-09-04 Thread Termoregolato
Il 03/09/20 22:16, Chris Angelico ha scritto: Hmm. Have you considered using CSS to do this? Markdown is generally fairly easy to style with CSS. Yes, infact these are files where I'll insert a tag (in the example , to show the errors find at a second revision due they are of another kind, b

Re: Regex to change multiple lines

2020-09-03 Thread Chris Angelico
On Fri, Sep 4, 2020 at 5:36 AM Termoregolato wrote: > > Il 03/09/20 16:10, Termoregolato wrote: > > > I need to change every occurrence of a sequence between two chars > > Thanks to all for your replies, it's time to learn regular expressions, > but now I've some valid pointers from you. > > The w

Re: Regex to change multiple lines

2020-09-03 Thread Termoregolato
Il 03/09/20 16:10, Termoregolato wrote: I need to change every occurrence of a sequence between two chars Thanks to all for your replies, it's time to learn regular expressions, but now I've some valid pointers from you. The work I must do here, to explain, is to get some markdown files, an

Re: Regex to change multiple lines

2020-09-03 Thread Tim Chase
Derp, sorry about the noise. I mistook this message for a similar dialog over on the Vim mailing list. For Python, you want re.sub(r"%%(.*?)%%", r"\1", s, flags=re.S) or put the flag inline re.sub(r"(?s)%%(.*?)%%", r"\1", s) -tim On 2020-09-03 09:27, Tim Chase wrote: > On 2020-09-03 16:1

Re: Regex to change multiple lines

2020-09-03 Thread Tim Chase
On 2020-09-03 16:10, Termoregolato wrote: > -- original > This is the %%text that i must modify%%, on a line, %%but also > on the others%% that are following > > I need to change to > > -- desidered > This is the text that i must modify, on a line, but > also on the others that are following Sho

Re: Regex to change multiple lines

2020-09-03 Thread Chris Angelico
On Fri, Sep 4, 2020 at 12:16 AM Termoregolato wrote: > > Hi. I've on file, containing multiple lines, and I need to change every > occurrence of a sequence between two chars, in this case "%%". > > -- original > This is the %%text that i must modify%%, on a line, %%but also > on the others%% that

Re: regex string matching python3

2018-10-01 Thread Brian J. Oney via Python-list
On Mon, 2018-10-01 at 10:49 -0700, nanman3...@gmail.com wrote: > I have a string like this:  >  > b'\tC:94.3%[S:89.9%,D:4.4%],F:1.7%,M:4.0%,n:1440\n' >  > And I would like to  extract the numbers corresponding to S,D,F and M in this > string and convert them into an array like this:  >  > [ '89.9'

Re: regex string matching python3

2018-10-01 Thread MRAB
On 2018-10-01 18:49, nanman3...@gmail.com wrote: I have a string like this: b'\tC:94.3%[S:89.9%,D:4.4%],F:1.7%,M:4.0%,n:1440\n' And I would like to extract the numbers corresponding to S,D,F and M in this string and convert them into an array like this: [ '89.9', '4.4', '1.7', '4.0'] Any he

Re: regex pattern to extract repeating groups

2018-08-27 Thread MRAB
On 2018-08-28 00:58, Malcolm wrote: On 28/08/2018 7:09 AM, John Pote wrote: On 26/08/2018 00:55, Malcolm wrote: I am trying to understand why regex is not extracting all of the characters between two delimiters. The complete string is the xmp IFD data extracted from a .CR2 image file. I do

Re: regex pattern to extract repeating groups

2018-08-27 Thread Malcolm
On 28/08/2018 7:09 AM, John Pote wrote: On 26/08/2018 00:55, Malcolm wrote: I am trying to understand why regex is not extracting all of the characters between two delimiters. The complete string is the xmp IFD data extracted from a .CR2 image file. I do have a work around, but it's messy a

Re: regex pattern to extract repeating groups

2018-08-27 Thread John Pote
On 26/08/2018 00:55, Malcolm wrote: I am trying to understand why regex is not extracting all of the characters between two delimiters. The complete string is the xmp IFD data extracted from a .CR2 image file. I do have a work around, but it's messy and possibly not future proof. Do you mean f

Re: regex pattern to extract repeating groups

2018-08-27 Thread Rob Gaddi
On 08/25/2018 04:55 PM, Malcolm wrote: I am trying to understand why regex is not extracting all of the characters between two delimiters. The complete string is the xmp IFD data extracted from a .CR2 image file. I do have a work around, but it's messy and possibly not future proof. Any insig

Re: Regex to extract multiple fields in the same line

2018-06-15 Thread Friedrich Rentsch
On 06/15/2018 12:37 PM, Ganesh Pal wrote: Hey Friedrich, The proposed solution worked nice , Thank you for the reply really appreciate that Only thing I think would need a review is if the assignment of the value of one dictionary to the another dictionary if is done correctly ( lines 17

Re: Regex to extract multiple fields in the same line

2018-06-15 Thread Nathan Hilterbrand
On Wed, Jun 13, 2018 at 4:08 AM, Ganesh Pal wrote: > Hi Team, > > I wanted to parse a file and extract few feilds that are present after "=" > in a text file . > > > Example , form the below line I need to extract the values present after > --struct =, --loc=, --size= and --log_file= > > Sample

Re: Regex to extract multiple fields in the same line

2018-06-15 Thread Ganesh Pal
> {'struct': 'data_block', 'log_file': '/var/1000111/test18.log', 'loc': > '0', 'size': '8'} > > MARB, as usual the solution you you look nice, Thanks for the excellent solutions >>> regex = re.compile (r"--(struct|loc|size|mirror|l og_file)\s*=\s*([^\s]+)") >>> regex.findall (line) [('struct

Re: Regex to extract multiple fields in the same line

2018-06-13 Thread Friedrich Rentsch
On 06/13/2018 07:32 PM, Ganesh Pal wrote: On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James wrote: On 13/06/18 09:08, Ganesh Pal wrote: Hi Team, I wanted to parse a file and extract few feilds that are present after "=" in a text file . Example , form the below line I need to extract t

Re: Regex to extract multiple fields in the same line

2018-06-13 Thread MRAB
On 2018-06-13 18:32, Ganesh Pal wrote: On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James wrote: On 13/06/18 09:08, Ganesh Pal wrote: Hi Team, I wanted to parse a file and extract few feilds that are present after "=" in a text file . Example , form the below line I need to extract the valu

Re: Regex to extract multiple fields in the same line

2018-06-13 Thread Ganesh Pal
On Wed, Jun 13, 2018 at 5:59 PM, Rhodri James wrote: > On 13/06/18 09:08, Ganesh Pal wrote: > >> Hi Team, >> >> I wanted to parse a file and extract few feilds that are present after "=" >> in a text file . >> >> >> Example , form the below line I need to extract the values present after >> --

Re: Regex to extract multiple fields in the same line

2018-06-13 Thread Rhodri James
On 13/06/18 09:08, Ganesh Pal wrote: Hi Team, I wanted to parse a file and extract few feilds that are present after "=" in a text file . Example , form the below line I need to extract the values present after --struct =, --loc=, --size= and --log_file= Sample input line = '06/12/2018 11

Re: Regex for changing :variable to ${variable} in sql query

2018-04-18 Thread zljubisic
On Wednesday, 18 April 2018 19:34:37 UTC+2, MRAB wrote: > > Hi, > > > > I have a sql query in which all variables declared as :variable should be > > changed to ${variable}. > > > > for example this sql: > > > > select * > > from table > > where ":x" = "1" and :y=2 > > and field in (:string)

Re: Regex for changing :variable to ${variable} in sql query

2018-04-18 Thread MRAB
On 2018-04-18 08:25, zljubi...@gmail.com wrote: Hi, I have a sql query in which all variables declared as :variable should be changed to ${variable}. for example this sql: select * from table where ":x" = "1" and :y=2 and field in (:string) and time between :from and :to should be tran

Re: RegEx to match set of lines

2018-04-05 Thread Terry Reedy
On 4/5/2018 11:03 AM, Steven D'Aprano wrote: On Thu, 05 Apr 2018 14:09:23 +0530, Prahallad Achar wrote: I would like to match set of lines from the below data. this data comes from one of the network Good grief! You don't need to post your entire data set! We don't need or want to see hundred

Re: RegEx to match set of lines

2018-04-05 Thread Steven D'Aprano
On Thu, 05 Apr 2018 14:09:23 +0530, Prahallad Achar wrote: > Hello, > I would like to match set of lines from the below data. this data comes > from one of the network Good grief! You don't need to post your entire data set! We don't need or want to see hundreds of lines. Cut your data down to

Re: Regex Doubts

2018-03-30 Thread Iranna Mathapati
Thanks a lot Antoon. On Fri, Mar 30, 2018 at 2:51 PM, Antoon Pardon wrote: > On 30-03-18 08:16, Iranna Mathapati wrote: > > Hi Team, > > > > > > how to achieve fallowing expected output? > > > > str_output= """ > > > > MOD1 memory : 2 valid1790 free > > MOD2 me

Re: Regex Doubts

2018-03-30 Thread Antoon Pardon
On 30-03-18 08:16, Iranna Mathapati wrote: > Hi Team, > > > how to achieve fallowing expected output? > > str_output= """ > > MOD1 memory : 2 valid1790 free > MOD2 memory : 128 valid 128 free > UDP Aware *MEMR*

Re: Regex Doubts

2018-03-30 Thread Cameron Simpson
On 30Mar2018 11:46, Iranna Mathapati wrote: how to achieve fallowing expected output? str_output= """ MOD1 memory : 2 valid1790 free MOD2 memory : 128 valid 128 free UDP Aware *MEMR*: 0 valid 0 free *

Re: Regex Doubts

2018-03-30 Thread Iranna Mathapati
Hi Cameron. str_output= """ MOD1 memory: 2 valid1790 free MOD2 memory: 128 valid 128 free UDP Aware MEMR : 0 valid0 free *MEMR* : 21 valid 491 free Feature XYZ

Re: Regex on a Dictionary

2018-02-15 Thread Andre Müller
Hello, this question also came up there: https://python-forum.io/Thread-Working-with-Dict-Object Greetings Andre -- https://mail.python.org/mailman/listinfo/python-list

Re: Regex on a Dictionary

2018-02-13 Thread Mark Lawrence
On 13/02/18 18:08, Stanley Denman wrote: On Tuesday, February 13, 2018 at 9:41:14 AM UTC-6, Mark Lawrence wrote: On 13/02/18 13:11, Stanley Denman wrote: I am trying to performance a regex on a "string" of text that python isinstance is telling me is a dictionary. When I run the code I get th

Re: Regex on a Dictionary

2018-02-13 Thread Stanley Denman
On Tuesday, February 13, 2018 at 9:41:14 AM UTC-6, Mark Lawrence wrote: > On 13/02/18 13:11, Stanley Denman wrote: > > I am trying to performance a regex on a "string" of text that python > > isinstance is telling me is a dictionary. When I run the code I get the > > following error: > > > > {'

Re: Regex on a Dictionary

2018-02-13 Thread Steven D'Aprano
On Tue, 13 Feb 2018 13:53:04 +, Mark Lawrence wrote: > Was the string methods solution that I gave a week or so ago so bad that > you still think that you need a regex to solve this? Sometimes regexes are needed, but often Jamie Zawinski is right: Some people, when confronted with a prob

Re: Regex on a Dictionary

2018-02-13 Thread Steven D'Aprano
On Tue, 13 Feb 2018 05:11:20 -0800, Stanley Denman wrote: > I am trying to performance a regex on a "string" of text that python > isinstance is telling me is a dictionary. Please believe Python when it tells you that something is a dictionary. Trust me, the interpreter knows. It doesn't matter

Re: Regex on a Dictionary

2018-02-13 Thread Mark Lawrence
On 13/02/18 13:11, Stanley Denman wrote: I am trying to performance a regex on a "string" of text that python isinstance is telling me is a dictionary. When I run the code I get the following error: {'/Title': '1F: Progress Notes Src.: MILANI, JOHN C Tmt. Dt.: 05/12/2014 - 05/28/2014 (9 p

Re: Regex on a Dictionary

2018-02-13 Thread alister via Python-list
On Tue, 13 Feb 2018 13:42:08 +, Rhodri James wrote: > On 13/02/18 13:11, Stanley Denman wrote: >> I am trying to performance a regex on a "string" of text that python >> isinstance is telling me is a dictionary. When I run the code I get >> the following error: >> >> {'/Title': '1F: Progres

Re: Regex on a Dictionary

2018-02-13 Thread Rhodri James
On 13/02/18 13:11, Stanley Denman wrote: I am trying to performance a regex on a "string" of text that python isinstance is telling me is a dictionary. When I run the code I get the following error: {'/Title': '1F: Progress Notes Src.: MILANI, JOHN C Tmt. Dt.: 05/12/2014 - 05/28/2014 (9 p

Re: Regex on a Dictionary

2018-02-13 Thread Etienne Robillard
Hi Stanley, Le 2018-02-13 à 08:11, Stanley Denman a écrit : x=MyRegex.findall(MyDict) How about: x = [MyRegex.findall(item) for item in MyDict] Etienne -- Etienne Robillard tkad...@yandex.com https://www.isotopesoftware.ca/ -- https://mail.python.org/mailman/listinfo/python-list

Re: Regex: Perl to Python

2016-03-07 Thread Fillmore
Big thank you to everyone who offered their help! On 03/06/2016 11:38 PM, Fillmore wrote: -- https://mail.python.org/mailman/listinfo/python-list

Re: Regex: Perl to Python

2016-03-06 Thread Peter Otten
Fillmore wrote: > > Hi, I'm trying to move away from Perl and go to Python. > Regex seems to bethe hardest challenge so far. > > Perl: > > while () { > if (/(\d+)\t(.+)$/) { > print $1." - ". $2."\n"; > } > } > > into python > > pattern = re.compile(r"(\d+)\t(.+)$") > with open(fiel

Re: Regex: Perl to Python

2016-03-06 Thread Rustom Mody
Also for regex hacking: Try with findall before using match/search -- https://mail.python.org/mailman/listinfo/python-list

Re: Regex: Perl to Python

2016-03-06 Thread Rustom Mody
Also for regex hacking: Try with findall before using match/search -- https://mail.python.org/mailman/listinfo/python-list

Re: Regex: Perl to Python

2016-03-06 Thread Terry Reedy
On 3/6/2016 11:38 PM, Fillmore wrote: Hi, I'm trying to move away from Perl and go to Python. Regex seems to bethe hardest challenge so far. Perl: while () { if (/(\d+)\t(.+)$/) { print $1." - ". $2."\n"; } } into python pattern = re.compile(r"(\d+)\t(.+)$") with open(fields_I

Re: Regex: Perl to Python

2016-03-06 Thread Chris Angelico
On Mon, Mar 7, 2016 at 3:38 PM, Fillmore wrote: > pattern = re.compile(r"(\d+)\t(.+)$") > with open(fields_Indexfile,mode="rt",encoding='utf-8') as headerfile: > for line in headerfile: > #sys.stdout.write(line) > m = pattern.match(line) > print(m.group(0)) > header

Re: regex recursive matching (regex 2015.07.19)

2015-08-19 Thread Ben Bacarisse
MRAB writes: > On 2015-08-18 22:55, Ben Bacarisse wrote: >> Neal Becker writes: >> >>> Trying regex 2015.07.19 >>> >>> I'd like to match recursive parenthesized expressions, with groups such that >>> '(a(b)c)' >>> >>> would give >>> group(0) -> '(a(b)c)' >>> group(1) -> '(b)' >>> >>> but that's

Re: regex recursive matching (regex 2015.07.19)

2015-08-18 Thread MRAB
On 2015-08-18 22:55, Ben Bacarisse wrote: Neal Becker writes: Trying regex 2015.07.19 I'd like to match recursive parenthesized expressions, with groups such that '(a(b)c)' would give group(0) -> '(a(b)c)' group(1) -> '(b)' but that's not what I get import regex #r = r'\((?>[^()]|(?R))*\)

Re: regex recursive matching (regex 2015.07.19)

2015-08-18 Thread Ben Bacarisse
Neal Becker writes: > Trying regex 2015.07.19 > > I'd like to match recursive parenthesized expressions, with groups such that > '(a(b)c)' > > would give > group(0) -> '(a(b)c)' > group(1) -> '(b)' > > but that's not what I get > > import regex > > #r = r'\((?>[^()]|(?R))*\)' > r = r'\(([^()]|(?

Re: regex recursive matching (regex 2015.07.19)

2015-08-18 Thread MRAB
On 2015-08-18 15:25, Neal Becker wrote: Trying regex 2015.07.19 I'd like to match recursive parenthesized expressions, with groups such that '(a(b)c)' would give group(0) -> '(a(b)c)' group(1) -> '(b)' but that's not what I get import regex #r = r'\((?>[^()]|(?R))*\)' r = r'\(([^()]|(?R))*\)

Re: regex recursive matching (regex 2015.07.19)

2015-08-18 Thread Terry Reedy
On 8/18/2015 10:25 AM, Neal Becker wrote: Trying regex 2015.07.19 I'd like to match recursive parenthesized expressions, with groups such that '(a(b)c)' Extended regular expressions can only match strings in extended regular languages. General nested expressions are too general for that. Yo

Re: Regex Python Help

2015-03-26 Thread Denis McMahon
On Wed, 25 Mar 2015 14:19:39 -0700, Gregg Dotoli wrote: > On Wednesday, March 25, 2015 at 4:36:01 PM UTC-4, Denis McMahon wrote: >> On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: >> >> > I am creating a tool to search a filesystem for one simple string. >> >> man grep >> >> STOP! REINVENTIN

Re: Regex Python Help

2015-03-25 Thread Terry Reedy
On 3/25/2015 7:10 PM, Steven D'Aprano wrote: Does Windows shell have grep? How about Powershell? No. I just use Idle's grep (Find in Files). And I generally would even if Command Prompt did have grep. Idle's has the nice feature that output goes in an Output Window, with each line found p

Re: Regex Python Help

2015-03-25 Thread Mark Lawrence
On 25/03/2015 23:10, Steven D'Aprano wrote: On Thu, 26 Mar 2015 08:19 am, Gregg Dotoli wrote: Grep is regular expressions. If I'm using Python, I'll use the Python modules. Silly It very well may be silly. You're using Python regular expressions because you're using Python. Why are you using

Re: Regex Python Help

2015-03-25 Thread Steven D'Aprano
On Thu, 26 Mar 2015 08:19 am, Gregg Dotoli wrote: > Grep is regular expressions. If I'm using Python, I'll use the Python > modules. Silly It very well may be silly. You're using Python regular expressions because you're using Python. Why are you using Python? Early in this thread you said "H

Re: Regex Python Help

2015-03-25 Thread Mark Lawrence
On 25/03/2015 21:19, Gregg Dotoli wrote: Grep is regular expressions. If I'm using Python, I'll use the Python modules. Silly Gregg Clear as mud, and please don't top post. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrenc

Re: Regex Python Help

2015-03-25 Thread Gregg Dotoli
Grep is regular expressions. If I'm using Python, I'll use the Python modules. Silly Gregg On Wednesday, March 25, 2015 at 4:36:01 PM UTC-4, Denis McMahon wrote: > On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: > > > I am creating a tool to search a filesystem for one simple string. > > man

Re: Regex Python Help

2015-03-25 Thread Denis McMahon
On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: > I am creating a tool to search a filesystem for one simple string. man grep STOP! REINVENTING! THE! WHEEL! Your new wheel will invariably be slower and less efficient than the old one. -- Denis McMahon, denismfmcma...@gmail.com -- https:/

Re: Regex Python Help

2015-03-25 Thread Gregg Dotoli
No worries Steven, Thanks to ALL on this thread. Gregg On Tuesday, March 24, 2015 at 9:43:58 PM UTC-4, Steven D'Aprano wrote: > On Wed, 25 Mar 2015 05:13 am, gdot...@gmail.com wrote: > > > The error is: > > > > SyntaxError: Missing parentheses in call to 'print' > > > I cannot imagine how

Re: Regex Python Help

2015-03-24 Thread Steven D'Aprano
On Wed, 25 Mar 2015 05:13 am, gdot...@gmail.com wrote: > The error is: > > SyntaxError: Missing parentheses in call to 'print' I cannot imagine how the message could be more explicit: the call to print is missing parentheses. If you're not going to read the error messages you are given, you are

Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Here you go. Windows shell was easier!!! for /f %a in (c:\gonow) do echo %a | c:\Python34\python c:\python34\unopy.py %a Now I can use any regex pattern, I need. On Tuesday, March 24, 2015 at 3:54:25 PM UTC-4, Rob Gaddi wrote: > On Tue, 24 Mar 2015 12:43:38 -0700, Gregg Dotoli wrote: > > > [c

Re: Regex Python Help

2015-03-24 Thread Terry Reedy
On 3/24/2015 2:13 PM, gdot...@gmail.com wrote: I am creating a tool to search a filesystem for one simple string. I cannot get the syntax correct. Thank you in advance for your help. import sys import re import os path='/' viewfiles=os.listdir(path) listdir is not recursive, so this code will

Re: Regex Python Help

2015-03-24 Thread Rob Gaddi
On Tue, 24 Mar 2015 12:43:38 -0700, Gregg Dotoli wrote: > [context snipped due to top posting] > > All I need is a loop, should I bag Python and use a simple shell for loop? Honestly, yes. You're not even using a regular expression, just a fixed string you're trying to search for. You can do

Re: Regex Python Help

2015-03-24 Thread Vincent Vande Vyvre
Le 24/03/2015 20:22, Gregg Dotoli a écrit : Thank you! But The print error is gone, but now the script quickly finishes and doesnt walk the OS tree or search. Gregg On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote: I am creating a tool to search a filesystem for one simple

Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
This works fine , but I have to pipe the filename to the script python stool I am creating a tool to search a filesystem for one simple string. > I cannot get the syntax correct. > Thank you in advance for your help. > > import sys > import re > import os > path='/' > viewfiles=os.listdir(path)

Re: Regex Python Help

2015-03-24 Thread Rob Gaddi
On Tue, 24 Mar 2015 12:10:24 -0700, Gregg Dotoli wrote: > > Thank you Gary, that got rid of the error, but now there is no tree > walk, it runs and immediatley finishes. I just need to grep each file. I > have this working with the windows "for /r %a and redirecting that to > Python, but want to u

Re: Regex Python Help

2015-03-24 Thread Skip Montanaro
On Tue, Mar 24, 2015 at 2:22 PM, Gregg Dotoli wrote: > The print error is gone, but now the script quickly finishes and doesnt > walk > the OS tree or search. > You need to walk the directory tree recursively. Take a look at os.walk(). Skip -- https://mail.python.org/mailman/listinfo/python-li

Re: Regex Python Help

2015-03-24 Thread Vincent Vande Vyvre
Le 24/03/2015 20:38, Vincent Vande Vyvre a écrit : Le 24/03/2015 20:22, Gregg Dotoli a écrit : Thank you! But The print error is gone, but now the script quickly finishes and doesnt walk the OS tree or search. Gregg On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote: I am

Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Thank you! But The print error is gone, but now the script quickly finishes and doesnt walk the OS tree or search. Gregg On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote: > I am creating a tool to search a filesystem for one simple string. > I cannot get the syntax correct.

Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Thank you Gary, that got rid of the error, but now there is no tree walk, it runs and immediatley finishes. I just need to grep each file. I have this working with the windows "for /r %a and redirecting that to Python, but want to use Python only. I do have dummy files with the regex string. Th

Re: Regex Python Help

2015-03-24 Thread Gary Herron
On 03/24/2015 11:13 AM, gdot...@gmail.com wrote: I am creating a tool to search a filesystem for one simple string. I cannot get the syntax correct. Thank you in advance for your help. import sys import re import os path='/' viewfiles=os.listdir(path) for allfiles in viewfiles: file= os.pat

Re: Regex Python Help

2015-03-24 Thread Skip Montanaro
On Tue, Mar 24, 2015 at 1:13 PM, wrote: > SyntaxError: Missing parentheses in call to 'print' It appears you are attempting to use a Python 2.x print statement with Python 3.x Try changing the last line to print(line.rstrip()) Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: regex help

2015-03-13 Thread Steven D'Aprano
Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal point, > but leave one zero if it's whole number. def strip_zero(s): if '.' not in s: return s s = s.rstrip('0') if s.endswith('.'): s += '0' return s And in use: py> strip_

Re: regex help

2015-03-13 Thread Cameron Simpson
On 13Mar2015 12:05, Larry Martell wrote: I need to remove all trailing zeros to the right of the decimal point, but leave one zero if it's whole number. For example, if I have this: 14S,5.,4.5686274500,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.75471698113207

Re: regex help

2015-03-13 Thread Larry Martell
On Fri, Mar 13, 2015 at 1:29 PM, MRAB wrote: > On 2015-03-13 16:05, Larry Martell wrote: >> >> I need to remove all trailing zeros to the right of the decimal point, >> but leave one zero if it's whole number. For example, if I have this: >> >> >> 14S,5.,4.5686274500,3.72727272

Re: regex help

2015-03-13 Thread Tim Chase
On 2015-03-13 12:05, Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal > point, but leave one zero if it's whole number. > > But I can't figure out how to get the 5. to be 5.0. > I've been messing with the negative lookbehind, but I haven't fou

Re: regex help

2015-03-13 Thread MRAB
On 2015-03-13 16:05, Larry Martell wrote: I need to remove all trailing zeros to the right of the decimal point, but leave one zero if it's whole number. For example, if I have this: 14S,5.,4.5686274500,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.75471698113207

Re: regex help

2015-03-13 Thread Thomas 'PointedEars' Lahn
Larry Martell wrote: > I need to remove all trailing zeros to the right of the decimal point, > but leave one zero if it's whole number. For example, if I have this: > > 14S,5.,4.5686274500,3.7272727272727271,3.3947368421052630,5.7307692307692308,5.7547169811320753,4.94230769

Re: regex tool in the python source tree

2014-12-19 Thread Rustom Mody
On Saturday, December 20, 2014 12:01:10 PM UTC+5:30, Rustom Mody wrote: > I remember seeing here (couple of weeks ago??) a mention of a regex > debugging/editing tool hidden away in the python source tree. > > Does someone remember the name/path? > > There are of course dozens of online ones...

Re: Regex substitution trouble

2014-11-05 Thread Eugene
massi_...@msn.com wrote: > Hi everyone, > > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) > Here is the problem, I'm trying to write a regex in order to substitute > all the occurences in the form $"

Re: Regex substitution trouble

2014-10-28 Thread Cameron Simpson
On 28Oct2014 04:02, massi_...@msn.com wrote: I'm not really sure if this is the right place to ask about regular expressions, but since I'm usin python I thought I could give a try :-) Here is the problem, I'm trying to write a regex in order to substitute all the occurences in the form $"some

Re: Regex substitution trouble

2014-10-28 Thread MRAB
On 2014-10-28 12:28, massi_...@msn.com wrote: Hi Chris, thanks for the reply. I tried to use look ahead assertions, in particular I modified the regex this way: newstring = re.sub(ur"""(?u)(\$\"[\s\w(?<=\\)\"]+\")""", subst, oldstring) but it does not work. I'm absolutely not a regex guru so I

Re: Regex substitution trouble

2014-10-28 Thread Tim
On Tuesday, October 28, 2014 7:03:00 AM UTC-4, mass...@msn.com wrote: > Hi everyone, > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) > Here is the problem, I'm trying to write a regex in order to substi

Re: Regex substitution trouble

2014-10-28 Thread TP
On Tue, Oct 28, 2014 at 4:02 AM, wrote: > Hi everyone, > > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) > Here is the problem, I'm trying to write a regex in order to substitute > all the occurences i

Re: Regex substitution trouble

2014-10-28 Thread Chris Angelico
(Please quote enough of the previous text to provide context, and write your replies underneath the quoted text - don't assume that everyone's read the previous posts. Thanks!) On Tue, Oct 28, 2014 at 11:28 PM, wrote: > Hi Chris, thanks for the reply. I tried to use look ahead assertions, in >

Re: Regex substitution trouble

2014-10-28 Thread massi_srb
Hi Chris, thanks for the reply. I tried to use look ahead assertions, in particular I modified the regex this way: newstring = re.sub(ur"""(?u)(\$\"[\s\w(?<=\\)\"]+\")""", subst, oldstring) but it does not work. I'm absolutely not a regex guru so I'm surely missing something. The strings I'm d

Re: Regex substitution trouble

2014-10-28 Thread Chris Angelico
On Tue, Oct 28, 2014 at 10:02 PM, wrote: > I'm not really sure if this is the right place to ask about regular > expressions, but since I'm usin python I thought I could give a try :-) Yeah, that sort of thing is perfectly welcome here. Same with questions about networking in Python, or file I/

Re: regex line by line over file

2014-03-27 Thread Peter Pearson
On Thu, 27 Mar 2014 06:41:55 -0700 (PDT), James Smith wrote: > On Thursday, March 27, 2014 1:32:03 AM UTC-4, Steven D'Aprano wrote: > >> - are you mistaken about the content of the file? >> >> I can't help you with the first. But the second: try running this: >> >> # line2 and pat as defined abov

Re: regex line by line over file

2014-03-27 Thread James Smith
On Thursday, March 27, 2014 9:41:55 AM UTC-4, James Smith wrote: > (134, False, '\' > "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:"Log Collection In > Progress",NONE:170035-6364-1048,:YEAR=2014,MODE=NONE"\\r\\n\'') > > > > Is the \r\n on the end of the line screwing it up

Re: regex line by line over file

2014-03-27 Thread James Smith
On Thursday, March 27, 2014 1:32:03 AM UTC-4, Steven D'Aprano wrote: > - are you mistaken about the content of the file? > > I can't help you with the first. But the second: try running this: > > # line2 and pat as defined above > filename = sys.argv[1] > with open(filename) as f: > for line

Re: regex line by line over file

2014-03-26 Thread Steven D'Aprano
On Wed, 26 Mar 2014 20:23:29 -0700, James Smith wrote: > I can't get this to work. > It runs but there is no output when I try it on a file. Simplify, simplify, simplify. Either you will find the problem, or you will find the simplest example that demonstrates the problem. In this case, the pro

Re: regex line by line over file

2014-03-26 Thread Chris Angelico
On Thu, Mar 27, 2014 at 3:14 PM, James Smith wrote: > I tried the re.M in the compile and that didn't help. Okay. Try printing out the repr of the line at the point where you have the commented-out write to stdout. That might tell you if there's some other difference. At that point, you'll know i

Re: regex line by line over file

2014-03-26 Thread Rustom Mody
On Thursday, March 27, 2014 8:53:29 AM UTC+5:30, James Smith wrote: > I can't get this to work. > It runs but there is no output when I try it on a file. > #!/usr/bin/python > import os > import sys > import re > from datetime import datetime > #logDir = '/nfs/projects/equinox/platformTools/RTLG

Re: regex line by line over file

2014-03-26 Thread James Smith
On Wednesday, March 26, 2014 11:23:29 PM UTC-4, James Smith wrote: > I can't get this to work. > > It runs but there is no output when I try it on a file. > > > > > > #!/usr/bin/python > > > > import os > > import sys > > import re > > from datetime import datetime > > > > #logDir =

Re: regex line by line over file

2014-03-26 Thread Chris Angelico
On Thu, Mar 27, 2014 at 2:23 PM, James Smith wrote: > re.M > p = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"') If you're expecting this to be parsed as a multiline regex, it won't be. Probing re.M doesn't do anything on its own; you have to pass it as an argument to compi

Re: regex multiple patterns in order

2014-01-20 Thread Mark Lawrence
On 20/01/2014 17:09, Neil Cerutti wrote: On 2014-01-20, Devin Jeanpierre wrote: On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence wrote: On 20/01/2014 16:04, Neil Cerutti wrote: I use regular expressions regularly, for example, when editing text with gvim. But when I want to use them in Python

Re: regex multiple patterns in order

2014-01-20 Thread Mark Lawrence
ces that are outside of your sphere of control prevent you from doing so? I don't see any way in which someone uncomfortable with the re module would magically find themselves perfectly at home with the regex module. The regex module is the re module with some extra features (and complexit

Re: regex multiple patterns in order

2014-01-20 Thread Rustom Mody
hat you'd like to use regex but other > > influences that are outside of your sphere of control prevent you from doing > > so? > I don't see any way in which someone uncomfortable with the re module > would magically find themselves perfectly at home with the regex > modu

Re: regex multiple patterns in order

2014-01-20 Thread Neil Cerutti
On 2014-01-20, Devin Jeanpierre wrote: > On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence > wrote: >> On 20/01/2014 16:04, Neil Cerutti wrote: >>> I use regular expressions regularly, for example, when >>> editing text with gvim. But when I want to use them in Python >>> I have to contend with the

Re: regex multiple patterns in order

2014-01-20 Thread Devin Jeanpierre
On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence wrote: > On 20/01/2014 16:04, Neil Cerutti wrote: >> I use regular expressions regularly, for example, when editing >> text with gvim. But when I want to use them in Python I have to >> contend with the re module. I've never become comfortable with >>

Re: regex multiple patterns in order

2014-01-20 Thread Mark Lawrence
On 20/01/2014 16:04, Neil Cerutti wrote: On 2014-01-20, Roy Smith wrote: In article , Ben Finney wrote: Be aware that regex is not the solution to all parsing problems; for many parsing problems it is an attractive but inappropriate tool. You may need to construct a more specific parser for y

  1   2   3   4   5   6   >