开发者

Turn a string into a regexp that matches the plain string, in DrScheme

开发者 https://www.devze.com 2022-12-12 04:20 出处:网络
I want to split a string based on a non-regular expression. My input is a plain string. So, for example, given the input \"hello.*there\" and \".*\", I want the result (\"hello\" \"there\").

I want to split a string based on a non-regular expression. My input is a plain string. So, for example, given the input "hello.*there" and ".*", I want the result ("hello" "there").

Doing this obv doesn't work:

(regexp-split (regexp sep) str))

since it will try to match the regular expression .*. How do I escape sep to nullify any rege开发者_高级运维xp-like patterns?


regexp-quote


Claudiu, many of the questions you have asked about PLT-Scheme are answered in the documentation. Not to say it's wrong to ask questions, sometimes you'll get a more in-depth answer here.

There are many documents in the set of documentation that comes with PLT-Scheme. There are 2 pieces of documentation you want to be familiar with:

  1. The PLT Scheme Guide. http://docs.plt-scheme.org/guide/index.html
  2. The PLT Scheme Reference: http://docs.plt-scheme.org/reference/index.html

Both are installed locally when you install PLT-Scheme (formerly called DrScheme).

The Guide is intended for those new to Scheme or PLT-Scheme. The Reference is more in depth.

Eli pointed to the link in the Reference documentation. The regexp-quote function is also mentioned is the much shorter and more readable Guide, here http://docs.plt-scheme.org/guide/regexp-intro.html along with mention of quoting special characters using \, as well as a link to the Reference documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消