PHP Regex to find a specific substring -
so basically, have big string other information, , somewhere @ end, have following structure of string:
62ac979d-5277d720 it numbers , uppercase letters. extract substring many lines of bigger strings contain @ different places. have tried:
preg_match('/^[\w]+$/', $string); but don't have experience regular expressions. can provide regex necessary or @ least tell me mistaken? thank time!
this regex should you,
([a-z\d]{8}-[a-z\d]{8}) in use
<?php $string = 'this 62ac979d-5277d720 whole string.'; preg_match_all('~([a-z\d]{8}-[a-z\d]{8})~', $string, $value); print_r($value[1]); your current regex fails suspect because of ^ , $. these mark start , end of string searching (or line if m modifier used). \w a-z, a-z, 0-9 , _. think care capital letters , want allow 1 dash. if target 8 characters can add {8} in place of +. () capture value found. first found value in $string $value[1][0].
demo: http://sandbox.onlinephpfunctions.com/code/c6b2c391d95c5454a3c7ea81d5ac4a3bb8e49aef
Comments
Post a Comment