Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^6: Splitting compound (concatenated) words )

by vit (Friar)
on May 17, 2012 at 14:34 UTC ( [id://971068]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Splitting compound (concatenated) words )
in thread Splitting compound (concatenated) words )

I sent you a private message, please check.
I understand these steps.
my $re1 = join '|', sort{ length( $b ) <=> length( $a ) }@subset; my $re2 = "($re1)?" x 20; my @found = $s =~ /^$re2$/; print join '|', @found; my @undefsRemoved = grep defined(), @found; print for @undefsRemoved;
Except $s =~ /^$re2$/; How can it match $s from the beginning to the end? And when match occurs how a part of the string which already matched is not considered any more. I understand that you somehow do it by iterations with repeated (xxxx|yyy|zz)? but cannot get it.

Replies are listed 'Best First'.
Re^7: Splitting compound (concatenated) words )
by BrowserUk (Patriarch) on May 17, 2012 at 14:52 UTC

    In the same way that this matches:

    $s = 'fred';; print for $s =~ /^(.)?(.)?(.)?(.)?(.)?(.)?$/;; f r e d Use of uninitialized value $_ in print at (eval 10) line 1, <STDIN> li +ne 2. Use of uninitialized value $_ in print at (eval 10) line 1, <STDIN> li +ne 2.

    Although there are 6 capture groups, and only 4 characters, the capture groups are optional because of the trailing '?' ((.)?).

    So long as the regex has more capture groups than the string contains matches, the regex will match as many as are available, and the remaining capture groups will (optionally) "match" nothing, and so return undefs.

    Does that clarify things?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://971068]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2024-04-23 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found