views:

126

answers:

1

How would I do regex matching in Erlang?

All I know is this: f("AAPL" ++ Inputstring) -> true.

The lines that I need to match "AAPL,07-May-2010 15:58,21.34,21.36,21.34,21.35,525064\n"

In Perl regex: ^AAPL,* (or something similar)

In Erlang?

+4  A: 

Use the re module, e.g.:

...
String = "AAPL,07-May-2010 15:58,21.34,21.36,21.34,21.35,525064\n",
RegExp = "^AAPL,*",
Options = [],
case re:run(String, RegExp, Options) of
  match -> ... ;
  nomatch -> ...
end,
...
3lectrologos
Equivalent to `re:run(String, RegExp)`
viraptor
How is this different to running => regexp:first_match(Line, "^AAPL,*" ) ?
portoalet
Well, it may not be different, but according to the regexp module documentation 'it has been obsoleted by the re module and will be removed in a future release'. So, you should definitely prefer the re module.
3lectrologos