Albert-Jan Roskam wrote:
> I was thinking it would also be possible to do (in Windows):
> import os.path
> os.path.sep = '/'
> os.path.normpath('c:\\beeh/foo\\bar/baz')
>
> But alas, this still creates normalized windows-style paths.
If your input data has only forward slashes you can keep it th
From: Tutor on behalf of
Alan Gauld via Tutor
Sent: Thursday, November 8, 2018 10:49 AM
To: tutor@python.org
Subject: Re: [Tutor] Regex for Filesystem path (Asad)
On 08/11/2018 02:55, Asad wrote:
> Why is it putting \ this breaks the unix path it should be:
>
> /a/b
On 08/11/2018 02:55, Asad wrote:
> Why is it putting \ this breaks the unix path it should be:
>
> /a/b/c/d/test/28163133/22326541 ===> for unix platform logs
>
> \a\b\c\d\test\28163133\22326541 ===> for windows platform logs
os.path.join uses the separator that is correct for your OS.
Sinc
uld
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Wed, 7 Nov 2018 19:21:58 +
> Subject: Re: [Tutor] Regex for Filesystem path (Asad)
> On 07/11/2018 15:56, Asad wrote:
> > Hi All,
> >
> > I tired seems its not working as required :
> >
> &
On 07/11/2018 15:56, Asad wrote:
> Hi All,
>
> I tired seems its not working as required :
>
> from os.path import dirname, join
>
> testdir = dirname("/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log")
Note that this will set testdir to
/a/b/c/d/test/test_2814__2018_10_05_12_12_
23456/789
Instead i need the script to go to the location :
/a/b/c/d/test/123456/789
Please advice .
Thanks,
> -- Forwarded message --
> From: Cameron Simpson
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Wed, 7 Nov 2018 06:47:33 +1100
> Subject: R
Hello,
There are specific operating system, path related modules in Python for
handling these scenarios.
You could try looking at os.path module.
On Tue, Nov 6, 2018 at 11:16 PM Asad wrote:
> Hi all ,
>
> Can you provide some advice and code for the following problem :
>
> I have a log
On 06/11/2018 19:47, Cameron Simpson wrote:
> It is better to just construct the required path. Chdir there requires a
> chdir back, and chdir affects all the relative paths your programme may
> be using.
>
> I'd use os.path.dirname to get '/a/b/c/d/test' and then just append to
> it with os.p
On 06Nov2018 18:10, Alan Gauld wrote:
>On 06/11/2018 13:13, Asad wrote:
>
>> Can you provide some advice and code for the following problem :
>
>The first thing is to go read the documentation for the os.path module.
>It is designed for reliable path manipulation.
>
>> /a/b/c/d/test/test_2
>>4) look for the latest file in the directory /a/b/c/d/test/123456/789
>
> Slightly more complex, you need the creation timestamp.
> You can find that with os.path.getctime() (or several
> other options, eg os.stat)
here's a trick you might be able to make use of:
somelist = generate-lis
On 06/11/2018 13:13, Asad wrote:
> Can you provide some advice and code for the following problem :
The first thing is to go read the documentation for the os.path module.
It is designed for reliable path manipulation.
> /a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log
>
> f3 = ope
Hi all ,
Can you provide some advice and code for the following problem :
I have a logfile to check for errors :
/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log
f3 = open ( r"/a/b/c/d/test/test_2814__2018_10_05_12_12_45/logA.log", 'r' )
st1 = f3.readlines ()
from the above log I
On 06/03/18 22:17, Albert-Jan Roskam wrote:
> But the way you wrote it, the generator expression just "floats"
Any expression can be used where a value is expected provided
that e3xpression produces a value of the required type.
A generator expression effectively produces a sequence and
the type
On Tue, Mar 06, 2018 at 10:17:20PM +, Albert-Jan Roskam wrote:
> > >>> all(c.isdigit() for c in '12c4')
> > False
>
> I never understood why this is syntactically correct. It's like two
> parentheses are missing.
>
> This I understand:
> all((c.isdigit() for c in '12c4'))
> Or this:
> all([
On Feb 27, 2018 09:50, Alan Gauld via Tutor wrote:
>
> On 27/02/18 05:13, Cameron Simpson wrote:
>
> > hard to debug when you do. That's not to say you shouldn't use them, but
> > many
> > people use them for far too much.
>
>
> > Finally, you could also consider not using a regexp for this part
On 27/02/18 09:50, Peter Otten wrote:
>> def all_digits(s):
>> return all(c.isdigit() for c in s)
>
> Note that isdigit() already checks all characters in the string:
Ah! I should have known that but forgot.
I think the singular name confused me.
> The only difference to your suggestion is
Alan Gauld via Tutor wrote:
> On 27/02/18 05:13, Cameron Simpson wrote:
>
>> hard to debug when you do. That's not to say you shouldn't use them, but
>> many people use them for far too much.
>
>
>> Finally, you could also consider not using a regexp for this particular
>> task. Python's "int"
On 27/02/18 05:13, Cameron Simpson wrote:
> hard to debug when you do. That's not to say you shouldn't use them, but many
> people use them for far too much.
> Finally, you could also consider not using a regexp for this particular task.
>
> Python's "int" class can be called with a string,
On Mon, Feb 26, 2018 at 11:01:49AM -0800, Roger Lea Scherer wrote:
> The first step is to input data and then I want to check to make sure
> there are only digits and no other type of characters. I thought regex
> would be great for this.
I'm going to quote Jamie Zawinski:
Some people, when
On Mon, 26 Feb 2018, Terry Carroll wrote:
Instead of looking fo re xcaprions..
Wow. That should read "Instead of looking for exceptions..." Something
really got away from me there.
--
Terry Carroll
carr...@tjc.com
___
Tutor maillist - Tutor@pyth
On Mon, 26 Feb 2018, Roger Lea Scherer wrote:
""" ensure input is no other characters than digits
sudocode: if the input has anything other than digits
return digits """
p = re.compile(r'[^\D]')
I'm not so great at regular expressions, but this regex appears to be
searching for a str
On 26Feb2018 11:01, Roger Lea Scherer wrote:
The first step is to input data and then I want to check to make sure
there are only digits and no other type of characters. I thought regex
would be great for this.
Many people do :-) They are a reasonable tool for an assortment of text
matching
The first step is to input data and then I want to check to make sure
there are only digits and no other type of characters. I thought regex
would be great for this. The program works great, but no matter what I
enter, the regex part does the same thing. By same thing I mean this:
RESTA
asons I want to do this in Python. I can and shall now.
Best regards
Ed
Original Message
*Subject: *Re: [Tutor] Regex ^$ not behaving as expected
*From: *Danny Yoo
*To: *Edmund Butterworth
*Cc: *Python Tutor Mailing List
*Date: *08/12/2016, 17:20:19
Following up:
Following up: drats! Detecting this conceptual TypeError is not
feasible under the current design, due to the choice of data
representation used in this API.
The reason is because the flags are being represented as integers, and
we're using bitwise operations to define the union of flags. That i
> I'm still somewhat confused as to what the regexp module is doing when
> passing a non-numeric count parameter. That looks like it should
> raise a TypeError to me, so perhaps someone needs to file a bug
> against the standard library? Unsure.
Ok, I'm filing a bug to the Python developers so
Hi Edmund,
For each of the cases that surprise you, next time, can you also say
what you expected to see? That can help us see where the confusion
lies; as it stands, if we have the same mental model as what's
happening in Python, then the results look correct to us. :P
I can guess at what you
Hello,
I am new to Python and trying to get to grips with the re regex module.
I’m running Python 3.4 under Debian Jessie with a Cinnamon desktop.
My understanding is that when the re.M flag is raised, |^| will match at
the beginning of the string and also at the beginning of each line
withi
On 08/04/2016 03:27 AM, Alan Gauld via Tutor wrote:
On 04/08/16 02:54, Jim Byrnes wrote:
Is the second example a special case?
phoneNumRegex = re.compile(r'(\(\d\d\d\)) (\d\d\d-\d\d\d\d)')
I ask because it produces the same results with or without the ' r '.
That's because in this specific
On 04/08/16 02:54, Jim Byrnes wrote:
> Is the second example a special case?
>
> phoneNumRegex = re.compile(r'(\(\d\d\d\)) (\d\d\d-\d\d\d\d)')
>
> I ask because it produces the same results with or without the ' r '.
That's because in this specific case there are no conflicts between
the regex
> On Aug 3, 2016, at 20:54, Jim Byrnes wrote:
>
> Is the second example a special case?
>
> phoneNumRegex = re.compile(r'(\(\d\d\d\)) (\d\d\d-\d\d\d\d)')
> mo = phoneNumRegex.search('My phone number is: (415) 555-4242.')
> print(mo.group(1))
> print()
> print(mo.group(2))
>
> I ask because it
On 08/03/2016 06:21 PM, Alan Gauld via Tutor wrote:
On 03/08/16 20:49, Jim Byrnes wrote:
Regular Expressions he talks about the python escape character being a
'\' and regex using alot of backslashes.
In effect there are two levels of escape character, python and
the regex processor. Unfortun
On 03/08/16 20:49, Jim Byrnes wrote:
> Regular Expressions he talks about the python escape character being a
> '\' and regex using alot of backslashes.
In effect there are two levels of escape character, python and
the regex processor. Unfortunately they both use backslash!
Python applies its
I am reading Automate The Boring Stuff With Python. In the chapter on
Regular Expressions he talks about the python escape character being a
'\' and regex using alot of backslashes. Then he says, However,
by putting an r before the first quote of the string value, you can
mark the string as a
On 06Jan2015 11:43, Norman Khine wrote:
i have the following code:
[...]
#t(" ")
gettext_re = re.compile(r"""[t]\((.*)\)""").findall
My first thought is: "[t]" can just be written "t"
[...]
so, gettext_re = re.compile(r"""[t]\((.*)\)""").findall is not correct as
it includes
results such
Norman Khine wrote:
> i have a blade template file, as
>
> replace page
> .row
> .large-8.columns
> form( method="POST", action="/product/saveall/#{style._id}" )
> input( type="hidden" name="_csrf" value=csrf_token )
> h3 #{t("Generate Product for")} #{tt(style.name)}
On Tue, Jan 06, 2015 at 11:43:01AM +, Norman Khine wrote:
> hello,
> i have the following code:
>
> import os
> import sys
> import re
>
> walk_dir = ["app", "email", "views"]
> #t(" ")
> gettext_re = re.compile(r"""[t]\((.*)\)""").findall
>
> for x in walk_dir:
[...]
The first step in effe
hello,
i have the following code:
import os
import sys
import re
walk_dir = ["app", "email", "views"]
#t(" ")
gettext_re = re.compile(r"""[t]\((.*)\)""").findall
for x in walk_dir:
curr_dir = "../node-blade-boiler-template/" + x
for root, dirs, files in os.walk(curr_dir, topdown=False):
On 30/09/2013 21:29, Leena Gupta wrote:
Hello,
I have a TSV file that has the city,state,country information in this
format:
Name Display name Code
San Jose SJC SJC - SJ (POP), CA (US)
San Francisco SFOSFO - SF, CA (US)
I need
On 30/9/2013 16:29, Leena Gupta wrote:
> Hello,
>
> I have a TSV file that has the city,state,country information in this
> format:
> Name Display name Code
> San Jose SJC SJC - SJ (POP), CA (US)
> San Francisco SFOSFO - SF, CA (
Hello,
I have a TSV file that has the city,state,country information in this
format:
Name Display name Code
San Jose SJC SJC - SJ (POP), CA (US)
San Francisco SFOSFO - SF, CA (US)
I need to extract the state and country for each
- Original Message -
> From: Oscar Benjamin
> To: Tutor@python.org
> Cc:
> Sent: Tuesday, June 18, 2013 12:42 PM
> Subject: Re: [Tutor] regex grouping/capturing
>
> On 18 June 2013 09:27, Albert-Jan Roskam wrote:
>> from pygments.lexer impor
On 18 June 2013 09:27, Albert-Jan Roskam wrote:
> from pygments.lexer import RegexLexer, bygroups from pygments.token import *
> class IniLexer(RegexLexer): name = 'INI' aliases = ['ini', 'cfg'] filenames =
> ['*.ini', '*.cfg'] tokens = { 'root': [ (r'\s+', Text), (r';.*?$', Comment),
> (r'\[.*
- Original Message -
> From: Andreas Perstinger
> To: "tutor@python.org"
> Cc:
> Sent: Friday, June 14, 2013 2:23 PM
> Subject: Re: [Tutor] regex grouping/capturing
>
> On 14.06.2013 10:48, Albert-Jan Roskam wrote:
>> I am trying to create a pygmen
On 14.06.2013 10:48, Albert-Jan Roskam wrote:
I am trying to create a pygments regex lexer.
Well, writing a lexer is a little bit more complex than your original
example suggested.
> Here's a simplfied example of the 'set' command that I would like to
> parse.
s = 'set workspace = 6148 he
- Original Message -
> From: Andreas Perstinger
> To: tutor@python.org
> Cc:
> Sent: Thursday, June 13, 2013 8:09 PM
> Subject: Re: [Tutor] regex grouping/capturing
>
> On 13.06.2013 17:09, Albert-Jan Roskam wrote:
>> I have a string of the form "requir
On 13.06.2013 17:09, Albert-Jan Roskam wrote:
I have a string of the form "required optional3 optional2 optional1
optional3" ('optional' may be any kind of string, so it's not simply
'optional\d+'.
I would like to use a regex so I can distinguish groups. Desired
outcome: ('required', 'optional3',
Hello,
I have a string of the form "required optional3 optional2 optional1 optional3"
('optional' may be any kind of string, so it's not simply 'optional\d+'.
I would like to use a regex so I can distinguish groups. Desired outcome:
('required', 'optional3', 'optional2', 'optional1', 'optiona
Hi,
On 17 April 2013 06:11, Jim Mooney wrote:
> > Generally the 2to3 script does an OK job. If you're using Windows it's
> > [Python_Dir]\Tools\Scripts\2to3.py.
> >
> > http://docs.python.org/3/library/2to3
>
>
> Thanks. I didn't know where to find it and though
On Wed, Apr 17, 2013 at 1:11 AM, Jim Mooney wrote:
2to3 loops.py
> File "", line 1
> 2to3 loops.py
>^
> SyntaxError: invalid syntax
The script 2to3.py is run from the system's terminal/console shell
(e.g. cmd or PowerShell on Windows), not the python shell.
If the current dire
> Generally the 2to3 script does an OK job. If you're using Windows it's
> [Python_Dir]\Tools\Scripts\2to3.py.
>
> http://docs.python.org/3/library/2to3
Thanks. I didn't know where to find it and thought I had to install it.
I opened a command window in my Python3
On Tue, Apr 16, 2013 at 9:02 PM, Jim Mooney wrote:
> So for online progs, examples, ebooks, etc, that still have Py 2
> examples I can copy, has anyone come up with a nice regex package to
> do most of the conversions and produce a mostly Py3 from a Py2? That
> might make some things a bit easier.
On Apr 16, 2013, at 21:02, Jim Mooney wrote:
> I already tried an example I copied from something online, in Py 2,
> that had a ton of print statements. So I did some fast search and
> replace to make them Py 3 with (), since I'm using Py 3. (Except Wing
> 101 won't do Replace All for some reas
I already tried an example I copied from something online, in Py 2,
that had a ton of print statements. So I did some fast search and
replace to make them Py 3 with (), since I'm using Py 3. (Except Wing
101 won't do Replace All for some reason I haven't figured out, so
it's a bit tedious)
So for
On Mon, Dec 24, 2012 at 2:51 AM, Albert-Jan Roskam wrote:
>
> First, check if the first character is a (unicode) letter
You can use unicode.isalpha, with a caveat. On a narrow build isalpha
fails for supplementary planes. That's about 50% of all alphabetic
characters, +/- depending on the version
>>Is the code below the only/shortest way to match unicode characters? I would
>>like to match whatever is defined as a character in the unicode reference
>>database. So letters in the broadest sense of the word, but not digits,
>>underscore or whitespace. Until just now, I was convinced that th
On Sat, Dec 22, 2012 at 11:12 PM, Steven D'Aprano wrote:
>
> No. You could install a more Unicode-aware regex engine, and use it instead
> of Python's re module, where Unicode support is at best only partial.
>
> Try this one:
>
> http://pypi.python.org/pypi/regex
Looking over the old docs, I cou
On 23/12/12 07:53, Albert-Jan Roskam wrote:
Hi,
Is the code below the only/shortest way to match unicode characters?
No. You could install a more Unicode-aware regex engine, and use it instead
of Python's re module, where Unicode support is at best only partial.
Try this one:
http://pypi.py
On Sat, Dec 22, 2012 at 9:53 PM, Albert-Jan Roskam wrote:
> Hi,
>
> Is the code below the only/shortest way to match unicode characters? I
> would like to match whatever is defined as a character in the unicode
> reference database. So letters in the broadest sense of the word, but not
> digits,
Hi,
Is the code below the only/shortest way to match unicode characters? I would
like to match whatever is defined as a character in the unicode reference
database. So letters in the broadest sense of the word, but not digits,
underscore or whitespace. Until just now, I was convinced that the r
I think you can do this:
a=[]
b=redata.split('::')
for e in b:
if e.find('@') != -1:
a.append(e.split('@')[1])
list a includes all the domain
在 2012年4月9日 上午5:26,Wayne Werner 写道:
> On Fri, 6 Apr 2012, Khalid Al-Ghamdi wrote:
>
> hi all,
>> I'm trying to extract the domain in the foll
On Fri, 6 Apr 2012, Khalid Al-Ghamdi wrote:
hi all,
I'm trying to extract the domain in the following string. Why doesn't my
pattern (patt) work:
>>> redata
'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul 31
15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 2
Khalid Al-Ghamdi wrote:
> I'm trying to extract the domain in the following string. Why doesn't my
> pattern (patt) work:
>
redata
> 'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul
> 31 15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 20:22:37
> 1987::ttw..
hi all,
I'm trying to extract the domain in the following string. Why doesn't my
pattern (patt) work:
>>> redata
'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul
31 15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 20:22:37
1987::ttw...@rpybrct.edu::559243357-6-7
Thank you Ramit. I updated my code since I am running 2.7.1+ on Ubuntu.
Best wishes,
Mina
On 11-10-25 08:02 AM, Prasad, Ramit wrote:
f = open(args.fname, 'r')
lines = f.readlines()
f.close()
If you are using Python 2.6+ you can use a context manager to automatically
close the file. That way
>f = open(args.fname, 'r')
>lines = f.readlines()
>f.close()
If you are using Python 2.6+ you can use a context manager to automatically
close the file. That way you never have to worry about closing any files!
with open(args.fname, 'r') as f:
lines = f.readlines()
Ramit
Ramit Prasad | J
Hi Marc,
Thank you. Following some of your suggestion, the rewrite below worked. I agree with your point on readability over
complexity. By grace I meant not convoluted or simpler. That's all. As a beginner, I find not knowing all the
existing functions, I end up re-inventing the wheel som
On Wed, Oct 19, 2011 at 12:06 PM, Marc Tompkins wrote:
> This approach also works in the event that the data wasn't all collected in
> order - i.e. there might be data for Ag111 followed by U235 followed by
> Ag111 again.
>
> Ahem... Of course, I meant "Ag47 followed by U235 followed by Ag47
agai
On Wed, Oct 5, 2011 at 11:12 AM, Mina Nozar wrote:
> Now, I would like to parse through this code and fill out 3 lists: 1)
> activity_time, 2) activity, 3) error, and plot the activities as a function
> of time using matplotlip. My question specifically is on how to parse
> through the lines con
Hello Wayne,
Thank you for your help and sorry for the delay in the response. I was caught up with other simulation jobs and didn't
get around to testing what you suggested until yesterday.
On 11-10-05 01:24 PM, Wayne Werner wrote:
On Wed, Oct 5, 2011 at 1:12 PM, Mina Nozar mailto:noz...@tri
On Wed, Oct 5, 2011 at 1:12 PM, Mina Nozar wrote:
>
> If there is a more graceful way of doing this, please let me know as well.
> I am new to python...
>
I just glanced through your email, but my initial thought would be to just
use regex to collect the entire segment that you're looking for
Hi everyone,
I am post processing data from the output of simulation of activities for various radionuclide produced in a reaction at
different times.
I have already combined the information from 13 files (containing calculated activities and errors for 13 different
times). The format of thi
Gerhardus Geldenhuis wrote:
> I am trying to write a small program that will scan my access.conf file
> and update iptables to block anyone looking for stuff that they are not
> supposed to.
>
> The code:
> #!/usr/bin/python
> import sys
> import re
>
> def extractoffendingip(filename):
> f =
2011/6/19 Gerhardus Geldenhuis
> f = open(filename,'r')
> filecontents = f.read()
>
Try f.read().splitlines() instead.
> tuples = re.findall(r'^(\d+\.\d+\.\d+\.\d+).*\"GET(.*)HTTP',
> filecontents)
>
This searches the beginning of the lines, but you downloaded the whole page
as one strin
Looking at the regex you have to match an IP address, I think you would
need to put a range limit on each of the four octets you are searching
for (as each one would be between 1 and 3 digits long.)
For example: r =
re.match(r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b",line) has worked for me.
Hi
I am trying to write a small program that will scan my access.conf file and
update iptables to block anyone looking for stuff that they are not supposed
to.
The code:
#!/usr/bin/python
import sys
import re
def extractoffendingip(filename):
f = open(filename,'r')
filecontents = f.read()
#19
Hugo Arts wrote:
> 2011/4/3 "Andrés Chandía" :
>>
>>
>> I continue working with RegExp, but I have reached a point for wich I
>> can't find documentation, maybe there is no possible way to do it, any
>> way I throw the question:
>>
>> This is my code:
>>
>> contents = re.sub(r'Á',
>> "A", contents
2011/4/3 "Andrés Chandía" :
>
>
> I continue working with RegExp, but I have reached a point for wich I can't
> find
> documentation, maybe there is no possible way to do it, any way I throw the
> question:
>
> This is my code:
>
> contents = re.sub(r'Á',
> "A", contents)
> contents = re.
I continue working with RegExp, but I have reached a point for wich I can't find
documentation, maybe there is no possible way to do it, any way I throw the
question:
This is my code:
contents = re.sub(r'Á',
"A", contents)
contents = re.sub(r'á', "a",
contents)
contents = re.sub(r'
Thanks Steve, your are, from now on, my guru
this is the final version, the
good one!
contents = re.sub(r'(|)(l|L|n|N|t|T)(|)', r"\2'" ,contents)
On Wed, March 30, 2011 17:27, Steve Willoughby wrote:
On 30-Mar-11 08:21,
"Andrés Chandía" wrote:
>
>
> Thanks Kushal
and Steve.
> I think it w
On 30-Mar-11 08:21, "Andrés Chandía" wrote:
Thanks Kushal and Steve.
I think it works,a I say "I think" because at the
results I got a strange character instead of the letter that should appear
this is
my regexp:
contents = re.sub(r'(|)(l|L|n|N|t|T)(|)', '\2\'' ,contents)
Remember that \2 i
Thanks Kushal and Steve.
I think it works,a I say "I think" because at the
results I got a strange character instead of the letter that should appear
this is
my regexp:
contents = re.sub(r'(|)(l|L|n|N|t|T)(|)', '\2\'' ,contents)
this is my input file content:
lomo
nomo
tomo
Lomo
Nomo
On 29-Mar-11 23:55, Alan Gauld wrote:
""Andrés Chandía"" wrote
in perl there is a way to reference previous registers,
$text =~ s/(l|L|n|N)<\/u>/$1e/g;
I'm looking for the way to do it in python
If you're using just a straight call to re.sub(), it works like this:
text = re.sub(r
""Andrés Chandía"" wrote
I'm new to this list, so hello everybody!.
Hi, welcome to the list.
Please do not use reply to start a new thread it confuses threaded
readers and may mean you message will not be seen. Also please
supply a meaningful subject (as above) so we can decide if it
looks
Albert-Jan Roskam wrote:
So the raw string \b means means "ASCII backspace". Is that another way of
saying that it means 'Word boundary'?
No.
Python string literals use backslash escapes for special characters,
similar to what many other computer languages, including C, do.
So when you typ
~~
________
From: Steven D'Aprano
To: Python Mailing List
Sent: Fri, February 18, 2011 4:45:42 AM
Subject: Re: [Tutor] regex questions
Albert-Jan Roskam wrote:
> Hello,
>
> I have a couple of regex questions:
>
> 1 -- In the code be
Albert-Jan Roskam wrote:
Hello,
I have a couple of regex questions:
1 -- In the code below, how can I match the connecting words 'van de' , 'van
der', etc. (all quite common in Dutch family names)?
You need to step back a little bit and ask, what is this regex supposed
to accomplish? What i
Hello,
I have a couple of regex questions:
1 -- In the code below, how can I match the connecting words 'van de' , 'van
der', etc. (all quite common in Dutch family names)?
2 -- It is quite hard to make a regex for all surnames, but easier to make
regexes for the initials and the connecting wor
On Tue, Jan 4, 2011 at 14:58, Steven D'Aprano wrote:
> Dave Angel wrote:
>
>> One hazard is if the string the user inputs has any regex special
>> characters in it. If it's anything but letters and digits you probably want
>> to escape it before combining it with your \\b strings.
>
> It is best
Dave Angel wrote:
One hazard is if the string the user inputs has any regex special
characters in it. If it's anything but letters and digits you probably
want to escape it before combining it with your \\b strings.
It is best to escape any user-input before passing it to regex
regardless.
On 01/-10/-28163 02:59 PM, Richard D. Moores wrote:
On Tue, Jan 4, 2011 at 11:57, Richard D. Moores wrote:
On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote:
Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually
searching RTF files, not TXT files.
I want to modify this script t
On Tue, Jan 4, 2011 at 11:57, Richard D. Moores wrote:
> On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote:
>> Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually
>> searching RTF files, not TXT files.
>>
>> I want to modify this script to handle searching on a word. So what,
>> f
On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote:
> Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually
> searching RTF files, not TXT files.
>
> I want to modify this script to handle searching on a word. So what,
> for example, should line 71 be?
OK, I think I've got it.
in pl
Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually
searching RTF files, not TXT files.
I want to modify this script to handle searching on a word. So what,
for example, should line 71 be?
Dick
___
Tutor maillist - Tutor@python.org
To unsu
On Tue, Jan 4, 2011 at 11:07 AM, Richard D. Moores wrote:
> A file has these 2 lines:
>
> alksdhjf ksjhdf kjshf dex akjdhf jkdshf jsdhf
> alkdshf jkashd flkjdsf index alkdjshf alkdjshf
>
> And I want the only line that contains the word "dex"
Ah! Then you want a slightly different Regex pattern.
On Tue, Jan 4, 2011 at 09:31, Brett Ritter wrote:
> On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores wrote:
>> regex = ".*" + search + ".*"
>> p = re.compile(regex, re.I)
>
> Just having "search" as your regex is fine (it will search for the
> pattern _in_ the string, no need to specify the ot
On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores wrote:
> regex = ".*" + search + ".*"
> p = re.compile(regex, re.I)
>
> in finding lines in a text file that contain search, a string entered
> at a prompt.
That's an inefficient regex (though the compiler may be smart enough
to prune the unneede
On Tue, Jan 4, 2011 at 07:55, Wayne Werner wrote:
> On Tue, Jan 4, 2011 at 9:37 AM, Richard D. Moores
> You could use (2.6+ I think):
> word = raw_input('Enter word to search for: ')
> with open('somefile.txt') as f:
> for line in f:
> if word in line:
> print line
I think
On Tue, Jan 4, 2011 at 9:37 AM, Richard D. Moores wrote:
> I use
>
> regex = ".*" + search + ".*"
> p = re.compile(regex, re.I)
>
> in finding lines in a text file that contain search, a string entered
> at a prompt.
>
> What regex do I use to find lines in a text file that contain search,
> where
I use
regex = ".*" + search + ".*"
p = re.compile(regex, re.I)
in finding lines in a text file that contain search, a string entered
at a prompt.
What regex do I use to find lines in a text file that contain search,
where search is a word entered at a prompt?
Thanks,
Dick Moores
__
1 - 100 of 210 matches
Mail list logo