Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find multiple occurrences of a string within big string
#1
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
#2
Use regular expression.

Macro Macro284
Code:
Copy      Help
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]
,
#3
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!
#4
It s ok I think I solved it now...thank you for your expert support


Forum Jump:


Users browsing this thread: 1 Guest(s)