Jump to content
php.lv forumi

bash - regex string - result array


EdgarsK

Recommended Posts

Hi,

 

man ir fails kura ir json strings.

 

Man vajaga izgrepot ara no {...},{...}... visus objektus kuros ir kaut kada veida teksts kuru mekleju, piemeram "Govs"

 

so, ja man teksts ir:

 

 

[{"a":123,"b":"riepa"},{"a":124,"b":"govs"},{"a":125,"b":"zivs"},{"a":126,"b":"lampa"},{"a":127,"b":"govs"},{"a":128,"b":"galds"}]

 

 

man rezultata jasanjem

0={"a":124,"b":"govs"}
1={"a":127,"b":"govs"}

 

kads ir kautko tadu darijis? centos visadi, ar awk, sed, grep .. laikam nemau tik labi.

 

Ideja ir skaidra +- 

 

\{(.*)govs(.*)\}
\{(.*)(\bGovs\b)(.*)\}
.. bet ka lai pareizi visu izdara ta lai izsaucot bash skriptu: script.sh MySearch es rezultata sanjemu pliku stringu ar visiem rezultatiem kuri matcoja
 
Paldies, ja kadam izddoas izdomat
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...