You can have negated character classes. [^abc]
matches any character that is NOT a
, b
, or c
. For your case, you might want [^a-zA-Z'.\s]{1,40}
Since your data is in XML tags, you will probably want to extract from those first. XML and regular expressions don't always mix well.
If you absolutely must deal with the XML tags in the regex you could try something like this:
<FirstName>([^a-zA-Z'.\s]{1,40})</FirstName><LastName>([^a-zA-Z'.\s]{1,40})</LastName>
Capture group 1 will be the first name, capture group 2 will be the last name.
Misread original question, if you want to match strings MORE than 40 characters, the length should be {41,}
not {1,40}
. This will ensure you only match on strings with more than 40 characters.