简体   繁体   中英

How i can parse next string:

I have next string and tring to get only Site Name string from each array

let text = '[[{"value":"Site Name"}]]AAAAAAAA[[{"value":"Site Name"}]]BBBB'

So, it would be looking like this:

Site NameAAAAAAAASite NameBBBB

I've tried something like

text.replace(/(\[[{"value":")(\w+)(\"}]])/g, '$2'))

but it didn't work

Pls help

Use

/\[{2}{"value":"(.*?)"/g

See regex proof . EXPLANATION

--------------------------------------------------------------------------------
  \[{2}                    '[' (2 times)
--------------------------------------------------------------------------------
  {"value":"               '{"value":"'
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    .*?                      any character except \n (0 or more times
                             (matching the least amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  "                        '"'

JavaScript :

 let text = '[[{"value":"Site Name"}]]AAAAAAAA[[{"value":"Site Name"}]]BBBB' const matches = text.matchAll(/\[{2}{"value":"(.*?)"/g) console.log( Array.from(matches, z => z[1]) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM