in reply to Re^2: words with numbers in them
in thread words with numbers in them

No need to split and grep, just simplify your regex :)

#!/usr/bin/perl use strict; use warnings; my $names = '1Petrus2 Joh4an Smit 2johnny99 Julius 789 one 2two three3 fo44ur ..5.. six seven, seven7, eight--8--nine '; while( $names =~ /(\S*\d\S*)/g ) { print "$1\n"; }

Replies are listed 'Best First'.
Re^4: words with numbers in them
by facebook (Initiate) on Aug 01, 2018 at 14:09 UTC

    I am trying to understand your regex, but i cannot understand why it is :

    $names =~ /(\S*\d\S*)/g )

    in stead of:

    $names =~ /(\S*\d+\S*)/g

    So i changed it and it seems this also works, so which is it?

      Either, because anything matched by \d will also be matched by \S