ChrisC123 Posted May 15, 2013 Share Posted May 15, 2013 I hate asking for help (some searches usually find the answer), but I can't figure this one out.... I need to strip a handful of possible characters off the end of a variable and have been playing with trim, str_replace and preg_replace with no luck. I can get them to work fine with a specific name/characters but not one that covers all possible options. Our employees desktop and laptops use a standard naming convention that could have multiple characters at the end of their device name which is based on their name. I am trying to strip off all characters to just get the employee name. Here are some examples of our devices name: JDOE JDOE_L JDOE-L JDOE-L2 (or any numeric range such as 2-9) JDOE2 (or any numeric range such as 2-9) I am trying to get only the JDOE from the device name. Any help would be great. Thanks! Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted May 15, 2013 Solution Share Posted May 15, 2013 So the criteria is "everything up to the first hyphen, underscore, or number"? if (preg_match('/^[^0-9_-]+/', $device, $matches)) { echo $matches[0]; }Or only letters? '/^[a-z]+/i' Quote Link to comment Share on other sites More sharing options...
ChrisC123 Posted May 15, 2013 Author Share Posted May 15, 2013 That worked perfectly! Thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.