Python has:
"""
line1
line2
line3
"""
How can I do this in Common Lisp?
This is just a regular string:
"
line1
line2
line3
"
You need to escape internal double quotes characters, though.
If you don't want to escape quotes, then you have to change the readtable. In fact, you could easily have the behavior you want (and more) by using the cl-interpol library, which defines a custom syntax for strings, notably different kind of outer delimiters.
CL-USER> (ql:quickload :cl-interpol)
...
CL-USER> (interpol:enable-interpol-syntax)
; No value
CL-USER> #?(some string)
"some string"
CL-USER> #?(some string with a "string" inside)
"some string with a \"string\" inside"
CL-USER> #?(some string with (nested (parentheses)))
"some string with (nested (parentheses))"
Related
I am writing my own completions for a program.
I would like to be able to complete quoted words, maintaining the double or single quotes in the completion.
#compdef foo
_foo {
local strings
strings=(\
foo\
bar\
'spam eggs')
_arguments \
{-s,--string}'[Select a string]:STR:(\""${strings[#]}"\")\
&& return 0
}
_foo
what I'd expect:
foo -s <TAB>
"foo" "bar" "spam eggs"
what it get:
\"foo\" \"bar\" \"spam\ eggs\"
I ended up trying different combinations of nested quotes and escapes almost brainlessly but with no luck, as I was not able to find the relevant docs (really, zsh docs are "dense")
Thank you!
Do you know a function that takes a Clojure string and converts it to a map. For example, if the function gets the string
:first "John" :last "Lukas" :city "London"
it returns a map with the previous key-value relations.
You can use the clojure.end/read-string function for this. It makes sure that nobody injects code to your system, but otherwise will parse clojure data structures. Prepend "{" and append "}" to make it a map, that can be parsed that way:
(def stringtoparse ":first \"John\" :last \"Lukas\" :city \"London\"")
(clojure.edn/read-string (str "{" stringtoparse "}"))
I am trying to find a solution to this simple Perl code using the CL-PPCRE Library:
if (/\p{Space}/){
print "This string has some spaces\n";
}
I am a newbie to CL-PPCRE and tried:
(scan "\\p{\\#Space}" "The String has some white spaces")
; I got an error saying property #/Space doesn't exists.
How can I execute an equivalent?
The perl regexp /\p{Space}/ matches more than just " ". cf \p{} docs
One approach is to just use the \s expression:
(cl-ppcre:scan "\\s" (format nil "hi~Cthere" #\return))
To use the whole unicode Space class:
(ql:quickload :cl-unicode)
(cl-ppcre:scan "\\p{Space}" (format nil "hi~Cthere" #\return))
See Unicode properties in the CL-PPCRE docs.
The cl-ppcre library does not require you (at least for space) to use any special constant.
(if (cl-ppcre:scan " " "alle meine entchen")
(FORMAT T "Does have spaces~%")
(FORMAT T "Does not have spaces~%"))
> Does have spaces
(if (cl-ppcre:scan " " "allemeineentchen")
(FORMAT T "Does have spaces~%")
(FORMAT T "Does not have spaces~%"))
> Does not have spaces
will do the trick.
I have a problem in CLEAN, how can I make lowercase all letter in a string? I can do it through an char array, but i need to do it with a string too.
I have the code below so far:
module Something
import StdEnv, StdLib
arrayLower:: [Char] -> [Char]
arrayLower[x:xs] = (map toLower [x:xs])
stringLower:: String -> String
stringLower_ = ""
stringLowers = toString (arrayLower s)
Start:: String
Start = stringLower"SSSsss"
Your first case
stringLower _ = ""
means that stringLower applied to anything is the empty string.
I'm surprised that you didn't get a warning for the redundant second case.
A String is an array (unboxed, so it's a {#Char}), and you say that you already know how to do this with arrays, but your arrayLower is defined for lists of Char ([Char]), not arrays.
This, using an array comprehension, works for me:
stringLower :: String -> String
stringLower s = {toLower c \\ c <-: s}
I'm new to regular expresions. I have a gigantic text. In the aplication, i need words of 4 characters and delete the rest. The text is in spanish. So far, I can select 4 char length words but i still need to delete the rest.
This is my regular expression
\s(\w{3,3}[a-zA-ZáéíóúäëïöüñÑ])\s
How can i get all words with 4 letters in asp.net vb?
/(?:\A|(?<=\P{L}))(\p{L}{4})(?:(?=\P{L})|\z)/g
Explanation:
Switch /g is for repeatedly search
\A is start of the string (not start of line)
\p{L} matches a single code point in the category letter
\P{L} matches a single code point not in the category letter
{n} specify a specific amount of repetition [n is number]
\z is end of string (not end of line)
| is logic OR operator
(?<=) is lookbehind
(?=) is lookahead
(?:) is non backreference grouping
() is backreference grouping
Using the character class provided above in another answer (\w does NOT match spanish word characters unfortunately).
You can use this for a match (it matches the reverse, basically matches everything that is NOT a 4-character word, so you can replace with " ", leaving only the 4-character words):
/(^|(?<=(?<=\W)[a-zA-ZáéíóúäëïöüñÑ]{4,4}(?=\W)))(.*?)((?=(?<=\W)[a-zA-ZáéíóúäëïöüñÑ]{4,4}(?=\W))|$)/gis
Approximated code in VB (not tested):
Dim input As String = "This is your text"
Dim pattern As String = "/(^|(?<=(?<=\W)[a-zA-ZáéíóúäëïöüñÑ]{4,4}(?=\W)))(.*?)((?=(?<=\W)[a-zA-ZáéíóúäëïöüñÑ]{4,4}(?=\W))|$)/gis"
Dim replacement As String = " "
Dim rgx As New Regex(pattern)
Dim result As String = rgx.Replace(input, replacement)
Console.WriteLine("Original String: {0}", input)
Console.WriteLine("Replacement String: {0}", result)
You can see the result of the regex in action here:
http://regexr.com?30n29
\[^a-zA-ZáéíóúäëïöüñÑ][a-zA-ZáéíóúäëïöüñÑ]{4}[^a-zA-ZáéíóúäëïöüñÑ]\g
Translated:
A non-letter, followed by 4 letters, followed by a non-letter. The 'g' indicated will match globally ... more than once.
Check out this link to find out more info on looping over your matches:
http://osherove.com/blog/2003/5/12/practical-parsing-using-groups-in-regular-expressions.html