Like Or Regex

liunx

Guest
For finding the records starting with a specific letter im using the LIKE 'a%' for example. But what would I do to find a record where the first character of a field is not a letter.. <br /><br />Thanks,<br />-Jacques<!--content-->
You don't say what language you are using, but general regex would be negated with a ^ so for none alpha it would be ^a-zA-Z<!--content-->
Oops... using mysql... Lets say the Field name is CustName what would be the syntax? Only looking for the first character.<br /><br />Thanks<!--content-->
You should be able to do the same thing in MySQL as you do for letters: LIKE '1%'<!--content-->
<!--quoteo(post=223839:date=Apr 18 2008, 08:58 AM:name=TCH-MikeJ)--><div class='quotetop'>QUOTE (TCH-MikeJ @ Apr 18 2008, 08:58 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=223839"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->You should be able to do the same thing in MySQL as you do for letters: LIKE '1%'<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />You can also search for records CONTAINING an alphanumeric string by using LIKE '%string%'.<br /><br />Regards<br /><br /><!--content-->
Right, I've been using the LIKE to search for strings in other areas, but I what im doing is listing contacts by the first letter of their name/company name. I have links for A through Z but some start with numbers or other characters and I was going to have that be its own link. So for each letter, im doing LIKE 'a%' etc.. through z.. but im looking for a name that doesn't start with a letter. so I dont think that LIKE would work.. Maybe im wrong.. but if someone could help me with the syntax that would be great.<br /><br />Again, what im looking for is to find CustName where the first letter is not a letter.<br /><br />Thanks..<!--content-->
Sorry, I misunderstood and thought you were looking for a specific first number.<br /><br />Then you want something like this:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->SELECT * FROM sometable WHERE CustName REGEXP '^[0-9]';<!--c2--></div><!--ec2--><br /><br />And if you wanted everything that doesn't start with a number:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->SELECT * FROM sometable WHERE CustName NOT REGEXP '^[0-9]';<!--c2--></div><!--ec2--><br /><br /><i><b>^</b> = beginning of string (not negate like Andy suggested) in standard regular expressions.</i><!--content-->
<img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tchrocks!.gif" style="vertical-align:middle" emoid=":tchrocks!:" border="0" alt="tchrocks!.gif" /> <br /><br />Excellent.. Thanks..<!--content-->
 
Back
Top