RegExMatch, how to get the first match Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
songdg
Posts: 600
Joined: 04 Oct 2017, 20:04

RegExMatch, how to get the first match

24 Apr 2024, 22:33

The result of SubPat[1] is "Computer memories and quantum futures@Can we save the world's coral", but I want the first match that's "Computer memories and quantum futures", when first encounter "@", how to do that?

Code: Select all

my_text := "Are our coastlines being washed away<Mushroom Coffee>Computer memories and quantum futures@Can we save the world's coral@Humanoid robots"
y := "<Mushroom Coffee>"
RegExMatch(my_text, y . "(.*)" . "@", &SubPat)
MsgBox SubPat[1]
User avatar
Seven0528
Posts: 390
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: RegExMatch, how to get the first match  Topic is solved

24 Apr 2024, 22:52

Code: Select all

my_text := "Are our coastlines being washed away<Mushroom Coffee>Computer memories and quantum futures@Can we save the world's coral@Humanoid robots"
y := "<Mushroom Coffee>"
RegExMatch(my_text, y . "(.*?)" . "@", &SubPat)
MsgBox SubPat[1]
Ungreedy. Makes the quantifiers *, ?, + and {min,max} consume only those characters absolutely necessary to form a match, leaving the remaining ones available for the next part of the pattern. When the "U" option is not in effect, an individual quantifier can be made non-greedy by following it with a question mark. Conversely, when "U" is in effect, the question mark makes an individual quantifier greedy.
 https://www.autohotkey.com/docs/v2/misc/RegEx-QuickRef.htm#Options :dance:
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
songdg
Posts: 600
Joined: 04 Oct 2017, 20:04

Re: RegExMatch, how to get the first match

25 Apr 2024, 05:36

Seven0528 wrote:
24 Apr 2024, 22:52

Code: Select all

my_text := "Are our coastlines being washed away<Mushroom Coffee>Computer memories and quantum futures@Can we save the world's coral@Humanoid robots"
y := "<Mushroom Coffee>"
RegExMatch(my_text, y . "(.*?)" . "@", &SubPat)
MsgBox SubPat[1]
Ungreedy. Makes the quantifiers *, ?, + and {min,max} consume only those characters absolutely necessary to form a match, leaving the remaining ones available for the next part of the pattern. When the "U" option is not in effect, an individual quantifier can be made non-greedy by following it with a question mark. Conversely, when "U" is in effect, the question mark makes an individual quantifier greedy.
 https://www.autohotkey.com/docs/v2/misc/RegEx-QuickRef.htm#Options :dance:
Thanks, much appreciated for your help and some tips.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: bhoot, enotsl, Milincho, songdg and 35 guests