473,396 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

re module - cannot make expression

Hi All!

I would like to match strings not beginning with '/webalizer'. How can I
do this?
The only one negation command is ^ inside [] but it cannot be used here.
I looked
over "re" examples on the net but I could not find an example about how
to match
"not beginning with" type expressions.

Thanks,

Laci 2.0

Jul 18 '05 #1
2 1053
Laszlo Zsolt Nagy wrote:
Hi All!

I would like to match strings not beginning with '/webalizer'. How can I
do this?
The only one negation command is ^ inside [] but it cannot be used here.
I looked
over "re" examples on the net but I could not find an example about how
to match
"not beginning with" type expressions.

Thanks,

Laci 2.0

You can do taht with Python re's. Look in the re documentation for
"negative lookahead assertion".

regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
Jul 18 '05 #2
Laszlo Zsolt Nagy wrote:
I would like to match strings not beginning with '/webalizer'. How can I
do this?


Are you sure you need a regular expression? The str.startswith method
is what I would normally use to solve this kind of problem:

py> lst = ['aax', 'abx', 'acx', 'aay', 'aby', 'acy']
py> [s for s in lst if not s.startswith('ab')]
['aax', 'acx', 'aay', 'acy']

If you do need a regular expression, Steve Holden's suggestion about
negative lookahead assertions is the right way to go:

py> s = 'aaxabxacxaayabyacy'
py> re.compile(r'(?!ab).{2}[xy]+').findall(s)
['aax', 'acx', 'aay', 'acy']

Steve
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
37
by: jwaixs | last post by:
arg... I've lost 1.5 hours of my precious time to try letting re work correcty. There's really not a single good re tutorial or documentation I could found! There are only reference, and if you...
2
by: Iouri | last post by:
I am using VS 2005 team edition. I cannot find Module in ASP.NET 2.0. It is not in the list of Visual Studio installed templates. Where is it? or what can I use to hold my global variables and...
3
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
10
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the other? Any help would be great Thanx in...
5
by: BigJohn | last post by:
I have upgraded my ASP.Net/VB solution from 2003 to 2005. In 2003 I had a VB Module with global functions referenced in virtually all ASP.Net VB modules. After the upgrade to 2005 the ASP.Net VB...
8
by: Ant | last post by:
Look at the following minimal example: ('Test', 'String') I would have expected this to produce: ('String') since (:?...) should be a non-capturing group. From the module reference:
4
by: rlntemp-gng | last post by:
I have one module where I would like to launch 2 different forms (that do exist), based on a form object and string that is passed into it. (prmTable is a string, not a table object simply because...
8
by: Stefano Sabatini | last post by:
Hi all, I'm encountering this while trying to implement a factory singleton method to generate objects. The singleton has a static map which binds a static creation function defined in each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.