Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^5: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...) (js)

by tye (Sage)
on Sep 14, 2007 at 06:36 UTC ( #638958=note: print w/replies, xml ) Need Help??


in reply to Re^4: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...) (js)
in thread Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)

Does that imply that Javascript has different capture semantics than perl?

No. It is just that match() returns the matched substrings, not the captured substrings. If //g in a list context could be told to return the matched substrings (what it does when there are no capturing parens), then the same solution would work in Perl.

A better JavaScript solution is actually: "ZBBBCZZ".match(/(.)\1*/g). No need for the second set of parens.

- tye        

  • Comment on Re^5: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...) (js)
  • Download Code

Replies are listed 'Best First'.
Re^6: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...) (??{})
by pKai (Priest) on Sep 22, 2007 at 10:54 UTC

    Telling m//g in list context to forget about the captures and just return the matches:

    @list = "ZBBCZZ" =~ /(??{'(.)\1*'})/g;

    or probably more exact: there are no captures m// can see

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://638958]
help
Chatterbox?
and God said, "Let Newton be!"...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2017-11-20 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (287 votes). Check out past polls.

    Notices?