javascript - Regex for one, two, three etc using Node.js -


i working on regex , facing 1 problem. not able finding one, two, three, 4 etc. in string using regex in node.js.

example: string contains time chapter 1 or chapter one. can find 1 not one.

 chapter 1  chapter 2  chapter 3  chapter 4  ..... 

how find number in words?

can 1 assist me?

you can try:

str = 'chapter one'; str.match(/chapter\s{1}(\w+)/); // or str.match(/chapter (\w+)/); // or, for: thirty 3 etc str.match(/chapter\s{1}(\w+(\s{1}\w+)?)/); 

will return ["chapter one", "one"].
pattern description:

/chapter\s{1}(\w+)/ chapter # match chapter (case sensitive) \s{1}   # 1 space (you can use <space>) (\w+)   # letter, @ least one. can refer 1 element in returned array 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -