RegEx SubPattern Help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

RegEx SubPattern Help

29 Mar 2016, 03:47

Hi Community :wave:

I am only able to get first one, not all subpatterns. (. As kids, they)

Code: Select all

SearchIn := "Short stories for kids are adventurous and interesting ways to teach your children about good morals and right conduct. As kids, they are at their formative years, that is why they need to be educated with good values to make them good fit for society and family.  Instead of purchasing at bookstores, you do not have to spend another dime with these free moral short stories specially prepared for kids. Our online short stories are brimming with lessons that your kid can use in life. These small English stories are not only entertaining, they teach children about several things in life. By reading a short story from this page every day, you can help your kid build values, as well as improve his reading comprehension skills."

code := "(\. \b\w.*?\b\b\w.*?\b\b\w.*?\b)"

RegExMatch(SearchIn, Code, m)

Loop 5
   MsgBox % m%A_Index%
I need to get first three words after a period.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: RegEx SubPattern Help

29 Mar 2016, 04:31

Try this:

Code: Select all

Haystack =
(Join`s
Short stories for kids are adventurous and interesting ways to teach your
children about good morals and right conduct. As kids, they are at their
formative years, that is why they need to be educated with good values to
make them good fit for society and family.

Instead of purchasing at bookstores, you do not have to spend another dime
with these free moral short stories specially prepared for kids. Our online
short stories are brimming with lessons that your kid can use in life. These
small English stories are not only entertaining, they teach children about
several things in life. By reading a short story from this page every day,
you can help your kid build values, as well as improve his reading
comprehension skills.
)

Needle := "(\. \b\w.*?\b\b\w.*?\b\b\w.*?\b)"
Pos := 0

While Pos := RegExMatch(Haystack, Needle, m, Pos + 1)
   MsgBox, %m%
I hope that helps.
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: RegEx SubPattern Help

29 Mar 2016, 04:42

Thanks a lot " wolf_II " :)

I wanted something this small, simple, and easy to understood.
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: RegEx SubPattern Help

29 Mar 2016, 07:54

Using the period may produce unexpected results, you're probably better off searching for words based on what is not whitespace.

Code: Select all

SearchIn := "Short stories for kids are adventurous and interesting ways to teach your children about good morals and right conduct. As kids, they are at their formative years, that is why they need to be educated with good values to make them good fit for society and family.  Instead of purchasing at bookstores, you do not have to spend another dime with these free moral short stories specially prepared for kids. Our online short stories are brimming with lessons that your kid can use in life. These small English stories are not only entertaining, they teach children about several things in life. By reading a short story from this page every day, you can help your kid build values, as well as improve his reading comprehension skills."
code := "s)\.\s+\K\S+\s+\S+\s+\S+"
pos=1
While	pos :=	RegExMatch(SearchIn,Code,m,pos+StrLen(m))
	MsgBox %	m
return
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: RegEx SubPattern Help

30 Mar 2016, 00:01

Hey "sinkfaze" Thanks a lot !
True Genius :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], RareUserGerman and 344 guests