[erlang-questions] regexp sux!

Michael McDaniel <>
Fri Mar 9 16:54:44 CET 2007


On Fri, Mar 09, 2007 at 01:54:12PM +0100, Torbjorn Tornkvist wrote:
> 
> As usual, the regexp module drive me nutts.
> I simply want to do the equivalent to:
> 
> # from a bash shell
> 
> xx="<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>".
> echo $xx | sed 's/\(.*xml\
> version=.*encoding="\)\([a-zA-Z0-9_-]*\).*/\2/'
> ISO-8859-1
> 
> So how do I do this with the regexp module ?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  though the above did not work in my bash shell ,
  $ bash --version
  GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)
  Copyright (C) 2005 Free Software Foundation, Inc.

  here is one way to get encoding ver w/regexp, though not
  fully reliable due to depending on fixed version length
  and depending on no whitespace between endcoding= and the
  version.
  

 1>  X="<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>".
 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>"

 2> {match, Start, Length} = regexp:match(X, "encoding=").
 {match,21,9}

 3> lists:sublist(X, Start+Length, 12).  % get past tag
 "\"ISO-8859-1\""


 I'm using R11B-3, Eshell V5.5.3


~Michael

> 
> Cheers, Tobbe
> 
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> !DSPAM:52,45f1597418341684014417!
> 
> 



More information about the erlang-questions mailing list