Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Node.js的一、二、三等的正则表达式_Javascript_Regex_Node.js - Fatal编程技术网

Javascript 使用Node.js的一、二、三等的正则表达式

Javascript 使用Node.js的一、二、三等的正则表达式,javascript,regex,node.js,Javascript,Regex,Node.js,我正在研究正则表达式,面临一个问题。我无法在node.js中使用正则表达式在字符串中找到一、二、三、四等 示例:字符串包含第1章或第1章中的某些时间。我能找到1个,但没有一个 Chapter one Chapter two Chapter three Chapter four ..... 如何在单词中找到数字 有人能帮我吗?你可以试试: str = 'Chapter one'; str.match(/Chapter\s{1}(\w+)/); // or str.match(/Chap

我正在研究正则表达式,面临一个问题。我无法在node.js中使用正则表达式在字符串中找到一、二、三、四等

示例:字符串包含第1章或第1章中的某些时间。我能找到1个,但没有一个

 Chapter one
 Chapter two
 Chapter three
 Chapter four
 .....
如何在单词中找到数字

有人能帮我吗?

你可以试试:

str = 'Chapter one';
str.match(/Chapter\s{1}(\w+)/);
// or
str.match(/Chapter (\w+)/);
// or, for: thirty three etc
str.match(/Chapter\s{1}(\w+(\s{1}\w+)?)/);
将返回
[“第一章”,“第一章]

图案说明:

/Chapter\s{1}(\w+)/
Chapter # will match only Chapter (case sensitive)
\s{1}   # one space (you can also use <space>)
(\w+)   # letter, at least one. You can refer to it as 1 element in returned array
/Chapter\s{1}(\w+)/
章节#仅与章节匹配(区分大小写)
\一个空格(您也可以使用)
(\w+)#字母,至少一个。可以将其称为返回数组中的1个元素

/章节(?:一|二|三|四|……)\b/
章节的最大数量是多少?此外,请向我们展示您的regexp到目前为止(即使它不工作)它是动态的。取决于书中的页数。我理解,但你需要一个限制,因为你基本上需要自己处理英文单词OK。。。我限制了600页(六百页)…如何找到二十二页、三十三页等。上面的模式在章节后得到一个字符串。。。。如果我有两个字符串?
str.match(/Chapter\s{1}(\w+(\s{1}\w+)/)。但它不会有太多的一百二十二。。。对你来说足够好吗?
{1}
的目的是什么?它只意味着一个空格<代码>\s
-空白,
{1}
-正好是一个字符。这能回答你的问题吗?