regex - How do you tell Ruby to stop scan after the 1st match of regular expression -


i have tried different examples provided still couldn't solve issue. here's example:

i wan ruby scan text , stop @ 1st occurrence of word happy

bigtext = "i happy. happy. happy too."  

i use "?" ruby stop continues scan , return 3 occurrences of "happy"

bigtext.scan(/happy?/)  

my version of ruby 2.0.0

^.*?happy 

you can use m or multiline mode.see demo.

https://regex101.com/r/of9hr9/12


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -