0

Q: How can I strip non-word characters from a string?

For an arbitrary string, how do I strip all characters with non-word syntax? Alternately, using a regexp, how do I strip out the non-alphabetic characters?

Hypothetical example:

(some-fnx "#here's a string!") ; => "heres a string"

Specific application:

I want to get a list of the LaTeX font commands without the markup syntax. The value of LaTeX-font-list is:

((1 "" "" "\\mathcal{" "}")
 (2 "\\textbf{" "}" "\\mathbf{" "}")
 (3 "\\textsc{" "}")
 (5 "\\emph{" "}")
 (6 "\\textsf{" "}" "\\mathsf{" "}")
 (9 "\\textit{" "}" "\\mathit{" "}")
 (13 "\\textmd{" "}")
 (14 "\\textnormal{" "}" "\\mathnormal{" "}")
 (18 "\\textrm{" "}" "\\mathrm{" "}")
 (19 "\\textsl{" "}" "\\mathbb{" "}")
 (20 "\\texttt{" "}" "\\mathtt{" "}")
 (21 "\\textup{" "}")
 (4 "" "" t))

I want to iterate through the nested lists in order to get returned values like "textbf", "textrm", etc., without the rest of the markup.

2

I'll go for the regex route:

(mapcar (lambda (item) (replace-regexp-in-string "\\W" "" (cadr item)))
        LaTeX-font-list)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.