Children's Mercy Hospital
Find a Doctor | Press Room | Careers | Directions & Locations

About Us | Contact Us | Giving to Children's Mercy
For Patients and Families   Your Child's Health   Clinical Services   |   For Health Care Professionals   Medical Education   Medical Research

Another regular expression tip (May 23, 2006). Category: Data management

I had a large text file and I had to find the first example of a line that did NOT begin with the letter A. That's easier said than done, but you can use some special symbols in regular expressions to do this. Just search for

  • ^[^A]

The first caret (^) tells you that you need to restrict your attention to strings that begin a new line. The meaning of the caret changes when it is inside brackets. Inside brackets, the caret means find anything except the following character.

If you wanted to search for any line that does not begin with a letter, use the following

  • ^[^A-Za-z]

To find the first line that does not begin with a blank, use

  • ^[^ ]

This webpage was written by Steve Simon and was last modified on 07/08/2008.