Posts: 66
Threads: 19
Joined: May 2015
06-12-2019, 12:53 PM
(This post was last modified: 06-12-2019, 12:55 PM by mancunian.)
How do i search for multiple occurrences of a string within a string please and return the text next to it (big string is a copy of web page)
e.g.
Big string to search with 4 lines=
"value 1= blue
value 2 = red
value 1 = green
value 3= black"
1. Search for ALL occurrences of value 1
Result=
"value 1= blue
value 1 = green"
OR
2. Search for all occurrences of value 3
Result=
"value 3 = black"
Thank you in advance
Posts: 12,091
Threads: 142
Joined: Dec 2002
Use regular expression.
Macro
Macro284
str s=
;value 1= blue
;value 2 = red
;value 1 = green
;value 3= black
ARRAY(str) a; int i
if(!findrx(s "\bvalue 1 *= *(\w+)" 0 4 a)) out "not found"; ret
out a.len
for i 0 a.len
,out a[1 i]
,
Posts: 66
Threads: 19
Joined: May 2015
06-12-2019, 02:47 PM
(This post was last modified: 06-12-2019, 03:21 PM by mancunian.)
Thank you I am almost there so if I am searching for the text"videoId":
in a web page which contains the text
"etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/Q5dSG-as1cEbMUWsXLanq54V6Ko\"",
"id": {
"kind": "youtube#video",
"videoId": "CzwmGvqfMG5"
},
"snippet": {
"publishedAt": "2019-05-30T04:03:26.000Z",
"videoId": "xjrlXK1L0G2"
"kind": "#searchResult",
"etag": "\"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/6yK-xf1Qr1I77nHKPhQel7F0JPM\"",
To return the videoID which are (2 of them)
CzwmGvqfMG5
xjrlXK1L0G2
what should the code be then please?
Sorry I really struggle with regular expressions!
Posts: 66
Threads: 19
Joined: May 2015
It s ok I think I solved it now...thank you for your expert support