Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to catch 2 words sequentially duplicated in a pattern

I would like to be able to catch duplicate words in this case "cancer cervical" because they are the only duplicate 2 words sequentially.

pattern "cancer cervical diane mortality cervical cancer cervical diane sea"

I use this Regular expression but still can't catch 2 sequentially duplicated words.

/(W|^)(.+)s2/ig
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

This should be able to do the job: /(w+sw.*)s.*1/ if you are dealing with words including numbers.

var string = "cancer cervical diane mortality cervical cancer cervical diane sea";
var regex = /(w+sw.*)s.*1/;
console.log(string.match(regex));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...