W3C home > Mailing lists > Public > public-qt-comments@w3.org > May 2003

back references in regexen

From: Tobias Reif <tobiasreif@pinkjuice.com>
Date: Wed, 21 May 2003 15:50:42 +0200
Message-ID: <3ECB8432.9090606@pinkjuice.com>
To: public-qt-comments@w3.org

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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 27 March 2012 18:14:24 GMT