cybercobra | Jerub: and yet the Rubyites drool over that |
Jerub | cybercobra: but that's because most of the 'cool' stuff in ruby is monkeyhacks. |
Cowmoo | haha |
Jerub | cybercobra: adding methods to built in types? monkeyhacks. modifying built in types? monkeyhacks. library doesn't do what you want? monkey hack it and call it a feature. |
Peper | pattern="%s(?!(-)?[a-zA-Z])" % (self.source) Can I somehow rule out lines beginning with foo? |
deltab | ^(?!foo) |
Peper | (in the regex) deltab: but in the same pattern? |
deltab | yes |
Peper | and I don't need to put anything in between? >>> re.sub("^(?!foo)bar(?!blah)","test","blah bar barblah") 'blah bar barblah' deltab: I would like to get "blah test barblah" can I somehow add (.*) to the regex but do not sub it? |
deltab | Peper: "blah bar barblah" doesn't start with 'bar' |
sproingie | you'll sub what you match. use a backref if you want to keep it |
Peper | re.sub("bar(?!blah)","test","blah bar barblah") 'blah test barblah' I want this, but omit lines starting with foo when I just add ^(?!foo) it breaks my match re.sub("(?!foo)(.*)bar(?!blah)","\g<1>test","bar bar barblah") 'bar test barblah' using \g removes all subs but last |
deltab | or you could use if not s.startswith('foo') |
Peper | yeah, but I wanted to do it with regex as I am working on whole files with re.MULTILINE sproingie: did you mean using /g in replace string? |
HydraPheetz | Would using an iterator be faster than using a for loops to read through a (rather long) list of files? |
marienz | err define "using an iterator" |
cyclicFifths | :D |
marienz | the most common way to use an iterator is by using a for loop. so one of us is misunderstanding something here :) |
HydraPheetz | hmm Bah, I might have gotten sidetracked with something |
Peper | >>> re.sub("^(?!foo)(?=.*)bar(?!blah)","test","blah blah bar bar barblah") 'blah blah bar bar barblah' why doesn't that work? |
sproingie | (?=.*) is completely meaningless |