addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Ruby/Regex Question

From: David H.
Sent on: Monday, May 21, 2012 2:24 AM
Hey Rubyists,

This is more of a regex inquiry, but it's in a Ruby context; I'm
working on porting* jsmin form C to a much smaller Ruby script and
using regex to do it. Currently, I'm attempting to do a conditional
replace of spaces according to Crockford's spec
(https://github.com...­):

"It omits spaces except when a space is preceded and followed by a
non-ASCII character or by an ASCII letter or digit, or by one of these
characters: \ $ _"

I figured this bit would take care of that:

compressed_js = uncompressed_js.gsub­(/[^[\x20-\x7Ea-zA-Z­0-9\$\\_]]
[^[\x20-\x7Ea-zA-Z0-­9\$\\_]]/) {
    |match| match.gsub(/ /, "")
}

I suspect that the regex itself might be checking for an OR condition
instead of the AND described in the spec. Would anyone know if that or
something else may be amis?

* Porting the minification parts without the syntax checking parts,
and adding support for combining multiple .js files into a single
bundle of fun. Code-in-progress here:
https://github.com...­

Love and kittens,

-- 
david [.dh] huerta
davidhuerta.me

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy