Reputation: 352
I'm trying to get regex to work to take everything after "test" and before "@" in an email so "[email protected] would become 12345.
I've got this far to get it to return everything before the "@" symbol. (Working in PHP)
!(\d+)@!
Upvotes: 0
Views: 173
Reputation: 67968
(?<=test-)[^@]+
You can try this.No need to use groups.See demo.
https://regex101.com/r/eZ0yP4/28
Upvotes: 2
Reputation: 4631
Try this
$input = '[email protected]';
$regexPattern = '/^test(.*?)\@/';
preg_match ($regexPattern, $input, $matches);
$whatYouNeed = $matches[1];
var_dump($whatYouNeed);
Upvotes: 0
Reputation: 59232
Either you can use capturing groups and use the regex
test-(\d+)@
and use $1
or use lookaheads and behinds like (?<=test-)\d+(?=@)
which will just match 12345
Upvotes: 3
Reputation: 2763
You want everything between test
and @
so don't use \d
.
$myRegexPattern = '#test([^@])*@#Ui';
preg_match ($myRegexPattern, $input, $matches);
$whatYouNeed = $matches[1];
Upvotes: 0