Re: regular expression to extract from the middle of a string
| From: | Dave Goodchild | Date: | Fri, 14 Jul 2006 14:47:37 +0000 |
| Subject: | Re: regular expression to extract from the middle of a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-239466@lists.php.net to get a copy of this message | ||
On 14/07/06, Steve Turnbull <steve.turnbull@yhgfl.net> wrote:
Hey folks I don't want to "just get you to do the work", but I have so far tried in vain to achieve something... I have a string similar to the following; cn=emailadmin,ou=services,dc=domain,dc=net I want to extract whatever falls between the 'cn=' and the following comma - in this case 'emailadmin'. Question(s); is this possible via a regular expression? does php have a better way of doing this? Some pointers would be greatly appreciated. Once I have working, I will be creating a function which will cater for this and will post to this list if anyone is interested? Cheers Steve I think you will have to use minimal matching to ensure you only grab the first sequence. the following pattern should do the trick:'/cn=(\w+,?) -- http://www.web-buddha.co.uk http://www.projectkarma.co.uk