Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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?

Replies are listed 'Best First'.
Re^5: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...) (js)
by tye (Sage) 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?
[erix]: Henry VIII has a lot to answer for :P
[LanX]: erix sure next time you miss a conference nearby we drop by ...
[LanX]: did you even go to the Dutch Perl Workshop in Utrecht?
[erix]: haha ok. I'm going to Glasgow though, and make a long road trip round the isles
[erix]: [Lanx} not the last time but the one before (there have been two)
[LanX]: when did you move to Utrecht, you used to live in a windmill on a dyke walking around in wooden shoes. ..
[LanX]: ... did you lie to me? OO
erix wouldn't mind a nice old windmill to live in... Mueller/Miller/ Molenaar

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-12-15 16:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (439 votes). Check out past polls.

    Notices?