Code: Select all
"videoId": "KhmrdFsY6Ls"
Here's the string I have so far that totally does not work:
Code: Select all
RegExMatch(VideoLengthRaw, "O)"videoId": "(\d+)"", RegExResultHoldover), VideoLength := RegExResultHoldover[1]
Code: Select all
"videoId": "KhmrdFsY6Ls"
Code: Select all
RegExMatch(VideoLengthRaw, "O)"videoId": "(\d+)"", RegExResultHoldover), VideoLength := RegExResultHoldover[1]
Code: Select all
text = "videoId": "KhmrdFsY6Ls"
RegExMatch(text, """.*?"".*?""(.*?)""", Matched)
msgbox, % Matched1
Hey! Is there any way to make it narrow and specific to the string? The issue is that there are a ton of of information in the text where I'm trying to regex it that have the same pattern as the string I need. Example:User wrote:Code: Select all
text = "videoId": "KhmrdFsY6Ls" RegExMatch(text, """.*?"".*?""(.*?)""", Matched) msgbox, % Matched1
So I specifically need to match the text between "videoId": " and the last ", because otherwise it catches any other string but the one I need (since many similar come before the one I'm looking to match)."nextPageToken": "CAEQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 245,
"resultsPerPage": 1
Code: Select all
text =
(
"nextPageToken": "CAEQAA",
"regionCode": "US",
"videoId": "KhmrdFsY6Ls"
"pageInfo": {
"totalResults": 245,
"resultsPerPage": 1
)
RegExMatch(text, "OmU).*videoId"":\s*?""(.*)"".*?", out)
MsgBox % out[1]
This does exactly what I need, THANK YOU so very, very, very much! You live you learn, as they say : )))))Odlanir wrote:Some like this ?Code: Select all
text = ( "nextPageToken": "CAEQAA", "regionCode": "US", "videoId": "KhmrdFsY6Ls" "pageInfo": { "totalResults": 245, "resultsPerPage": 1 ) RegExMatch(text, "OmU).*videoId"":\s*?""(.*)"".*?", out) MsgBox % out[1]
@adamas, this seems to work too:adamas wrote:.
Code: Select all
text =
(
"nextPageToken": "CAEQAA",
"regionCode": "US",
"videoId": "KhmrdFsY6Ls"
"pageInfo": {
"totalResults": 245,
"resultsPerPage": 1
)
RegExMatch(text, """videoId"".*?""(.*?)""", Matched)
MsgBox % Matched1
Odlanir wrote:.
@adamas,adamas wrote:.
Odlanir wrote:.
the code below explains what I mentioned in the post above:adamas wrote:.
Code: Select all
text =
(
"nextPageToken": "CAEQAA",
"regionCode": "US",
"videoId": "KhmrdFsY6Ls"
"pageInfo": {
"totalResults": 245,
"resultsPerPage": 1
)
RegExMatch(text, "OmU).*videoId"":\s*?""(.*)"".*?", out)
MsgBox % "adamas Example: `n`n" out[0]
MsgBox % "adamas Example: `n`n" out[1]
RegExMatch(text, """videoId"".*?""(.*?)""", Matched)
MsgBox % "My example: `n`n" Matched
MsgBox % "My example: `n`n" Matched1
@User: Are you sure ? I've tested my RegEx with a 10MB file and I've found any problem, it performed exactly like your RegEx. Only two different approaches.The @Odlanir example is not very suitable because regex must match all the text in order to get (KhmrdFsY6Ls)!
(if your original text is too large, it may cause regex limit errors!)
So do you really think that forcing regex to match all the 10 MB text only to get "KhmrdFsY6Ls" string is the best way to go?Odlanir wrote:.
Code: Select all
FileRead, text, test99.txt ; <--- 10MB file
RegExMatch(text, """videoId"".*?""(.*?)""", Matched)
strx := "User example : `n`nMatched`t" Matched "`nMatched1`t" Matched1 "`n`n"
RegExMatch(text, "OmU).*videoId"":\s*?""(.*)"".*?", out)
strx .= "Odlanir example : `n`nout[0]`t" out[0] "`nout[1]`t" out[1]
clipboard := strx
User example :
Matched "videoId": "KhmrdFsY6Ls"
Matched1 KhmrdFsY6Ls
Odlanir example :
out[0] "videoId": "KhmrdFsY6Ls"
out[1] KhmrdFsY6Ls
What sample is not correct my friend?Odlanir wrote:.
Code: Select all
text =
(
"nextPageToken": "CAEQAA",
"regionCode": "US",
"videoId": "KhmrdFsY6Ls"
"pageInfo": {
"totalResults": 245,
"resultsPerPage": 1
)
Code: Select all
RegExMatch(VideoData, "OmU).*videoId"":\s*?""(.*)"".*?", RegExResultHoldover) VideoId := RegExResultHoldover[1]
Code: Select all
"videoId": "GlUrz6NYXRE"
Code: Select all
"publishedAt": "2018-02-15T04:00:01.000Z",
Code: Select all
line = "publishedAt": "2018-02-15T04:00:01.000Z"
MsgBox % substr(RegExReplace(line, ".*publishedAt"":\s*?""(.*)"".*?", "$1") ,1,10)
THANK YOU so very, very, very much much! This really helps a ton and first and foremost allows me to learn and better understand AutoHotkey's regex!Odlanir wrote:Code: Select all
line = "publishedAt": "2018-02-15T04:00:01.000Z" MsgBox % substr(RegExReplace(line, ".*publishedAt"":\s*?""(.*)"".*?", "$1") ,1,10)
Code: Select all
MyVariableNameHere := SubStr(RegExReplace(VariableThatHasMyStringToProcess, ".*publishedAt"":\s*?""(.*)"".*?", "$1") ,1,10)
Users browsing this forum: peter_ahk and 149 guests