Posts mit dem Label ruby werden angezeigt. Alle Posts anzeigen
Posts mit dem Label ruby werden angezeigt. Alle Posts anzeigen

Dienstag, 15. September 2020

Non greedy regular expression

Every time I'm using regular expressions in a script I need to look up the special things. Somethings which bothers me every other quarter or so is to write a non-greedy regexp. I once asked a question on Stackoverflow years ago and received a good response. Here it comes for those who cannot find the SO entry. Assuming the following string from a LDAP entry:
    CN=steffenr,OU=Users,OU=Accounts,DC=big-company,DC=com
I need the part between the '=' and the first comma.

The naive approach in Ruby is

But this gives us "CN=steffenr,OU=Users,OU=Accounts,DC=big-company" because the algorithms is greedy. What we want is to stop before the first comma. The solution is to use a negative look-ahead.

rubular.com offers an interactive console to debug a regexp. Voilá.

Donnerstag, 14. November 2013

Ruby, Savon with WSDL, Nokogiri

A very simple example on how to call a SOAP Web service with Ruby and Savon. The call returns a XML document. Nokogiri helps to extract the data we're interested in.


Mittwoch, 16. November 2011

How to use Nokogiri with XML namespace in Ruby

I recently wanted to fetch some data published by the ECB in XML format. Ruby + Nokogiri were very handy doing it. The tricky thing was to include the namespace in the XPath query.