How to detect \. in Markdown string

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to detect \. in Markdown string

Lloyd R. Prentice-2

Hello,

 

Daring Fireballs Markdown specification notes :

"1986. What a great season.

In other words, a number-period-space sequence at the beginning of a line. To avoid this, you can backslash-escape the period:

1986\. What a great season."

https://daringfireball.net/projects/markdown/syntax#block

But darned if I can find an Erlang function to distinguish these two cases:

2> S = "1986\. What a great season.".
"1986. What a great season."
3>
3> string:chr(S, "\.").
** exception error: no function clause matching string:chr("1986. What a great season.",".") (string.erl, line 97)
4> string:chr(S, "$\.").
** exception error: no function clause matching string:chr("1986. What a great season.","$.") (string.erl, line 97)
Yada yada

Indeed it looks like the escape character isn't even represented in the string.

Can anyone please show me the way?

Best wishes,

LRP

 

 

 

*********************************************
My books:

THE GOSPEL OF ASHES
http://thegospelofashes.com

Strength is not enough. Do they have the courage
and the cunning? Can they survive long enough to
save the lives of millions?

FREEIN' PANCHO
http://freeinpancho.com

A community of misfits help a troubled boy find his way

AYA TAKEO
http://ayatakeo.com

Star-crossed love, war and power in an alternative
universe

Available through Amazon or by request from your
favorite bookstore


**********************************************


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to detect \. in Markdown string

Richard A. O'Keefe-2

> On 21/06/2017, at 5:03 PM, <[hidden email]> <[hidden email]> wrote:
>
> But darned if I can find an Erlang function to distinguish these two cases:
>
> 2> S = "1986\. What a great season.".
> "1986. What a great season."

\. is just dot.  If you want a \ in there, you need \\.

T = "1986\\. What a great season."


> 3>
> 3> string:chr(S, "\.").

As the name suggests, string:chr wants a *character* as
its second argument.  You have given it a *string*.

1> T = "1986\\. What a great season.".
"1986\\. What a great season."
2> string:chr(T, $.).                
6
3> string:str(T, "\\.").
5

The Erlang reference manual, section 3.15, lists all the
defined character escape sequences.  Anything NOT in
that list is NOT a defined escape sequence and you use
it at your peril.  It is a pity that sequences like \.
and \E are not reported as errors or at least warnings.


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...