Oh oh. Github seemed to have major issue on Saturday from ~4.30pm PST. It is has been down for while now :(. The site status page https://status.github.com/ is showing
And main site
http://cdn.jpillora.com/js/jp-prettify.js Last few months I started woking in Greenplum/ postgres environment and was pleasantly surprised to see the regular expression capabilities. Compared to Mysql (5.1) it has quite advanced RE features. For example I ended up using the following query to strip the decimal numbers from another string.
SELECT
bucket_string
,substring(qty_bucket, 7, 1)::integer as bucket_num
,regexp_replace(bucket_string, '^Bucket\\d{1,}_(\\d{1,})([-+].*)?', E'\\1')::integer as minimum_qty
,regexp_replace(regexp_replace(bucket_string, '.*-(\\d{1,})', E'\\1'), '.*_(\\d{1,})([+]?)$', E'\\1')::integer
as maximum_qty
FROM a_table
ORDER BY bucket_string
And more with regexp_matches and array selection. I wanted to select offset number of days from 2012 December 01 in this simplified example. The offset is a text in another external table of Greenplum and data is not always clean and could have some text before the offset.
SELECT d
regexp_matches(d, '(?:.*_)?(\\d+)$') re_ary
, '2012-12-01'::date+((regexp_matches(d, '(?:.*_)?(\\d+)$'))[1] || 'days')::interval new_d
FROM
(
SELECT '90' d
union
SELECT 'new_90' d
union
SELECT 'old_90_10' d
) tt
returns
d re_ary new_d
-------------------------------------
90 {90} 2013-03-01 00:00:00
new_90 {90} 2013-03-01 00:00:00
new_90_10 {10} 2012-12-11 00:00:00