Sorry, I know that this is probably the wrong section to post this question in, but I'm sort of confused as to which one would have been appropriate. Anyways, I've been using regular expressions to find specific information such as e-mail addresses and whatnot inside textfiles, but I can't get my head over this one problem.

The problem my expression faces, is getting it to stop looking at a string. I was wondering if there's anyway I could expand the NOT parameters to include entire strings, rather then just one character.

For example, given the string:

Only pick up strings without Capital letters!

My regular expression would get:

Only pick up strings without Capital letters!

Any help would be great :D

I wrote this little function in Python. It scans a string and returns True the moment it finds a capital letter, otherwise False. Hope this helps ...

# tested with Python24

def hasCap(s):
    """returns True if the string s contains a capital letter"""
    for num in range(65, 91):  # A to Z
        capLetter = chr(num)
        if capLetter in s:
            return True
    return False

str1 = 'Only pick up strings without Capital letters!'
str2 = 'only pick up strings without capital letters!'

# test the function hasCap()
if hasCap(str1):
    print "str1 has a capital letter"
else:
    print "str1 has no capital letter"

if hasCap(str2):
    print "str2 has a capital letter"
else:
    print "str2 has no capital letter"

Thanks, that's exactly what I want it to do, except I'm trying to do that using Regular Expressions. Is there a way I could change the anchors (^ and $) so that it reads the beginning of every string, rather then at the beginning of every file?

Thanks for your help. :mrgreen:

It took me quite a while, but I found out how to do it. Just in case anyone else has similar problems, what I did was I made an or statement that said the first letter had to be a space, followed by a capital, or a capital at the start of a string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.