strip end off of string

Wes James comptekki@REDACTED
Tue May 4 18:54:22 CEST 2010


I see that fist ++ rest below will match the first part of the string
and the put the rest in "Rest":

-module(t).

-export([gett/0]).

gett() -> t("<INPUT TYPE=\"hidden\" NAME=\"xyz\" VALUE=\"some_string\">").

t("<INPUT TYPE=\"hidden\" NAME=\"xyz\" VALUE=\"" ++ Rest) ->
	t2(Rest).

t2(First ++ "\">") ->
      io:format("~s~n", [First]).


But in t2 is there something like that?  I can do string:substr(Str,
1, length(Str)-2).  I'm guessing from what I've seen in examples, that
erlang is a first | rest way of doing things. or use some re:run
expressoin.  I'm trying to pull out some_string.

I tried some experiments with some_string\">:

G="some_string\">".
"some_string\">"
110> re:run("(?<VAL>.*)\">", [caseless,{capture,['VAL'],list}]).
** exception error: bad argument
     in function  re:run/2
        called as re:run("(?<VAL>.*)\">",[caseless,{capture,['VAL'],list}])

112> erlang:erl_scan(G).
** exception error: undefined function erlang:erl_scan/1
113> erl_scan:string(G).
{error,{1,erl_scan,{string,34,">"}},1}

thx,

-wes


More information about the erlang-questions mailing list