back references in regexen

about
http://www.w3.org/TR/xmlschema-2/#regexs

Hi

It would be very handy to have a back reference mechanism in the regexen 
spec use by XSLT etc. Much more succinct code could be written. (unless 
I miss an existing feature)

Demo

  code = "foo = 'bar'"
  # also works when " is used as attribute value delimiter

  code =~ /([^\s=]+)(\s*)(=)(\s*)(['"])([^\5]+)(\5)/

  (1..7).each do |i|
    print i.to_s+': '
    p eval('$'+i.to_s)
  end

brings

  ruby backref.rb
  1: "foo"
  2: " "
  3: "="
  4: " "
  5: "'"
  6: "bar"
  7: "'"


A concrete Use Case

Marking up XML code listings.

XSLT: (slightly outdated)
http://www.pinkjuice.com/howto/vimxml/xslt/tinydbk2xhtml/markup_xml.xslt2
Sample output:
http://www.pinkjuice.com/howto/vimxml/intro.xml (at the bottom)

Tobi

-- 
http://www.pinkjuice.com/

Received on Wednesday, 21 May 2003 09:52:09 UTC