Regexp and shielded char in schema

in the circuit

there is a line "hello hellu-#\"hella.helloo,hallo#\return#\""

I want to list them as ("hello" "hellu" "hella" "helloo" "hallo")

separate space, hyphen, double quote, dot, comma, return

I tried

(regexp-split #rx"( +)|(#\-)|(#\")|(#\.)|(,)|(#\return)" string)

but #\- , #\.make a mistake

any hint or solution?

thank

+3
source share
1 answer

It looks like you are mixing character syntax ( #\foo) with string syntax, and you are doing this in both string and regexp. Therefore, I assume that the line you want to split is actually:

"hello hellu-\"hella.helloo,hallo\n\""

\" \n . , ( , ) regexp :

(regexp-split #rx"( +)|(\-)|(\")|(\.)|(,)|(\n)" string)

, \- \. (Racket C- escape-), :

(regexp-split #rx"( +)|(-)|(\")|(.)|(,)|(\n)" string)

, . "any char" , . , , , , , , :

> (define string "hello hellu-\"hella.helloo,hallo\n\"")
> (regexp-split #rx"( +)|(-)|(\")|(\\.)|(,)|(\n)" string)
'("hello" "hellu" "" "hella" "helloo" "hallo" "" "")

-, : :

(regexp-split #rx" +|-|\"|\\.|,|\n" string)

, | s, " ":

(regexp-split #rx" +|[-\".,\n]" string)

, , - ( ) , . , , , , :

(regexp-split #rx" +|[-\".,\n]+" string)

( -, ). :

> (define string "hello hellu-\"hella.helloo,hallo\n\"")
> (regexp-split #rx"[- \".,\n]+" string)
'("hello" "hellu" "hella" "helloo" "hallo" "")

, , , , . , , . Racket regexp-match*, , :

> (define string "hello hellu-\"hella.helloo,hallo\n\"")
> (regexp-match* #rx"[- \".,\n]+" string)
'(" " "-\"" "." "," "\n\"")

, , , , , . , - , , :

> (define string "hello hellu-\"hella.helloo,hallo\n\"")
> (regexp-match* #rx"[^- \".,\n]+" string)
'("hello" "hellu" "hella" "helloo" "hallo")
+3

All Articles