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

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

by erroneousBollock (Curate)
on Sep 13, 2007 at 14:47 UTC ( #638813=note: print w/ replies, xml ) Need Help??


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

It works just fine. Try pasting the following into your url bar:

   javascript:alert("ZBBBCZZ".match(/((.)\2*)/g))

That should alert the output of .toString() called on the array result.
If you have Firefox use the following to see the unadulterated array source:

   javascript:alert(("ZBBBCZZ".match(/((.)\2*)/g)).toSource())

-David

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


Comment on Re^4: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...) (js)
Select or Download Code
Re^5: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...) (js)
by tye (Cardinal) on Sep 14, 2007 at 06:36 UTC
    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        

      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://638813]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-09-18 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (123 votes), past polls