[erlang-questions] How best to resolve apparent inconsistency between re:run and string:slice

Scott Finnie Scott.Finnie@REDACTED
Thu Aug 29 13:09:31 CEST 2019

Thanks for the response Dan,

>> What I'm trying to achieve is consistent behaviour that (a) recognises  > any newline (CR, LF, CRLF, ...) at the start of the string and removes  > it.  I also need a count of the contiguous newlines found.

>Regular expressions seem needlessly complicated for this task.

In the example I gave, I'd agree.  In reality there are quite a few lexemes that constitute a newline.  The full regex is "^(?>\r\n|\n|\x0b|\f|\r|\x85)".  Adding a function clause for each of those would mean quite a lot of code duplication.  There is perhaps a halfway house though, where it matches on a regex but doesn't rely on the {From, To} match result in taking the new string slice.

It still leaves unresolved the seeming inconsistency between re:run and string:slice - though I appreciate you focused on suggesting an approach to my 1st order problem, not the 2nd order symptom.

Thanks again for your suggestion.


erlang-questions mailing list


Hymans Robertson LLP is a limited liability partnership registered in
England and Wales with registered number OC310282. A list of
members of Hymans Robertson LLP is available for inspection at One
London Wall, London, EC2Y 5EA, the firm's registered office. Hymans
Robertson LLP is authorised and regulated by the Financial Conduct
Authority and licensed by the Institute and Faculty of Actuaries for
a range of investment business activities.

This e-mail and any attachments are confidential. If it is not intended for
you then please tell us and respect that confidentiality. E-mails and
attachments can be corrupted or altered after sending: if you rely on
advice or product transmitted by e-mail then you do so at your own
risk. This footnote also confirms that this email message has been swept
for the presence of computer viruses.

Visit hymans.co.uk/information/privacy-notice/<http://www.hymans.co.uk/information/privacy-notice/> for
details of how we use your personal information.

More information about the erlang-questions mailing list