I am sorry, I think I am still misunderstanding it.

When I try:

(regexp-try-match #rx"^[1-9]+[0-9]*$" (current-input-port))

It also results immediately in:

 #f

> "^" doesn't match the beginning of the input

Is there something else I should use to start matching from the
beginning of whatever I input?

The docs for regexp-try-match say:

> This procedure is especially useful with a pattern that begins with a
start-of-string ^or with a non-#f end-pos, since each limits the amount
of peeking into the port.

To me it sounds like: 'Use this when you want to do "^somethingsomething".'

If I leave away the ^ part:

(regexp-try-match #rx"[1-9]+[0-9]*$" (current-input-port))

It again never stops wanting more input on REPL.


On 22.04.2018 14:34, Matthew Flatt wrote:
> Try `regexp-try-match`.
>
> The `regexp-match` function on an input port consumes non-matching
> input, which means that it consumes all input if a pattern that starts
> "^" doesn't match the beginning of the input.
>
> (This behavior is mentioned in the docs for `regexp-match`, but the
> docs have to say so many things that it's easy to overlook that
> detail.)
>
> At Sun, 22 Apr 2018 05:03:18 -0700 (PDT), Zelphir Kaltstahl wrote:
>> I am trying to match a whole string, to be an integer number.
>>
>> My thinking is, that an integer starts with a non zero digit and then goes 
>> on with an arbitrary number of digits (including zero).
>> I put it in a regexp as follows:
>>
>> (regexp-match #rx"[1-9]+[0-9]*" (current-input-port))
>>
>> But this is not correct, as Racket will try to match this anywhere in the 
>> string. For example it will give me the list containing "1" as a result 
>> when I input "01". I have to specify, that it shall match the whole string. 
>> So I add ^ and $ to it:
>>
>> (regexp-match #rx"^[1-9]+[0-9]*$" (current-input-port))
>>
>> But when I try this on the REPL, it never stops wanting to receive more 
>> input. No matter how many times I press the enter key, it only jumps to a 
>> new line, expecting more input.
>> On 
>> https://docs.racket-lang.org/reference/regexp.html#%28def._%28%28quote._~23~25k
>> ernel%29._regexp-match%29%29 
>> under 4.7.1 circumflex and dollar sign are said to be start and end, so I 
>> am not sure what I am doing wrong.
>> Is it the fact that the input stream does not really end and begin?
>>
>> When I try:
>>
>> (regexp-match #rx"[1-9]+[0-9]*" (read-line (current-input-port) 'any))
>>
>> I get immediately #f, as if I already entered something. (OK I pressed 
>> enter to run that line of code …)
>>
>> How do I solve this problem?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to