;-------exeample script-----------
text =
(
abcd10A00b1
accc20A20b2
ZZZZ30AXXXX40ACCCC
)
Result := RegexReplace(text,"U).*(\d{2}A).*", "$1 ")
;--------------------------------
Result = 10A 20A 30A 40A CCCC
But I Want..
Result = 10A 20A 30A 40A
How?
RegexReplace(?) Topic is solved
Re: RegexReplace(?)
Try this:I hope that helps.
Code: Select all
text =
(
abcd10A00b1
accc20A20b2
ZZZZ30AXXXX40ACCCC
)
Loop, Parse, text, `n, `r
{
p := 1
While p := RegexMatch(A_LoopField, "U).*(\d{2}A).*", $, p + StrLen($))
Result .= $1 " "
}
MsgBox, % Result
Re: RegexReplace(?) Topic is solved
The last two characters .* of your regex has no effect. Because .* matches zero or more characters, and the ungreedy option "U" make it match as short as it can, so it chooses zero character.Result := RegexReplace(text,"U).*(\d{2}A).*", "$1 ")
So your regex can be shorten into "U).*(\d{2}A)", also same as ".*?(\d{2}A)".
Below code works, which added a second match .+$.
Code: Select all
result := RegExReplace(text, ".*?(\d{2}A)|.+$", "$1 ")
Re: RegexReplace(?)
Hi wolf_II
You can remove the Loop, Parse:
You can remove the Loop, Parse:
Code: Select all
text =
(
abcd10A00b1
accc20A20b2
ZZZZ30AXXXX40ACCCC
)
p := 1, m := ""
While p := RegexMatch(text, "\d{2}A", m, p + StrLen(m))
Result .= m " "
MsgBox, % Result
Re: RegexReplace(?)
wolf_II
tmplinshi
Thank you.
많은 도움이 되었습니다. 감사합니다.
tmplinshi
Thank you.
많은 도움이 되었습니다. 감사합니다.
- HinkerLoden
- Posts: 93
- Joined: 23 Mar 2016, 07:50
- GitHub: HinkerLoden
Re: RegexReplace(?)
2 Questions
1.) Is there a usefull Tutorial for this RegEx
2.) Why should i use this instead of the given intern functions
1.) Is there a usefull Tutorial for this RegEx
2.) Why should i use this instead of the given intern functions
Re: RegexReplace(?)
I can't guarantee it in all situations but it works for this one:
Code: Select all
text =
(
abcd10A00b1
accc20A20b2
ZZZZ30AXXXX40ACCCC
)
MsgBox % RegExReplace(RegExReplace(text,"`am)^\D*|[^\A]*$"),"A\K.*?(?=\d{2}A)"," ")
Re: RegexReplace(?)
I don't know if it was useful but I had written a series of posts as a beginner's tutorial for RegEx at the original old forums. When those forums were upgraded the post formatting was destroyed and the posts were pretty much useless. And even though these forums are similar to the original old forums, it would still take a considerable amount of time to clean out the pieces of deprecated post formatting and make them workable here, which I just don't have the time to do right now.HinkerLoden wrote:1.) Is there a useful Tutorial for this RegEx
HinkerLoden wrote:2.) Why should i use this instead of the given intern functions
- RegExReplace() is an intern function,
- In this particular scenario literal matching would take a little more thought than pattern matching, but it is an interesting exercise to figure out:
Code: Select all
text =
(
abcd10A00b1
accc20A20b2
ZZZZ30AXXXX40ACCCC
)
While p := InStr(text,"A",1,1,A_Index)
{
n := SubStr(text,p-2,2)
if n is number
out .= n "A "
}
MsgBox % Trim(out)
-
- Posts: 132
- Joined: 22 Apr 2016, 06:50
Re: RegexReplace(?)
try this.oneHinkerLoden wrote: 1.) Is there a usefull Tutorial for this RegEx
Who is online
Users browsing this forum: a1987zz, Aggronaught, Bing [Bot], mikeyww, Netocon and 41 guests