regular expression confusion \s and “ ”

不问归期 提交于 2021-02-05 04:56:07

问题


In regular expression, i know when use \s to represent a space, but, in following case, would they be different:

  1. /a\sb/ ---with a \s
  2. /a b/ ---with empty field

thanks a lot if you can explain to me.


回答1:


The \s character class matches all "whitespace characters," not just spaces. This includes tabs (\t), and if multiline matching is allowed, it includes carriage return (\r) and newline (\n). Theoretically, if your regular expression engine handles unicode, there are also unicode whitespace characters that \s can match, though your mileage may vary.

So with a string like "a\t b", you can match it with the regex /a\s+b/, in case that is useful to you.



来源:https://stackoverflow.com/questions/10842835/regular-expression-confusion-s-and

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!