-1

I have this sentence:

Objet[id=100,name=car,type=grey,source=sourceId{id=12,version=12},linked=true]

I would like to isolate the result of the equality. Which give me something like that:

100
car
grey
sourceId{id=12,version=12}
true

As you can see the difficulty is because of the field source, which contain also equality but I don't want to split them. (Otherwise I would use \w*(=).)

Chris
  • 17
  • 4
  • What language? Please tag accordingly. –  Nov 24 '15 at 12:44
  • Possible duplicate of [Learning Regular Expressions](http://stackoverflow.com/questions/4736/learning-regular-expressions) – Welbog Nov 24 '15 at 16:38

2 Answers2

0

Regex: /\w+=(\w+\{.*?\})|\w+=(\w+)/g

Solution for above requirement can be done easily in Perl one liner:

perl -le '$str = "Objet[id=100,name=car,type=grey,source=sourceId{id=12,version=12},linked=true]"; print "$2$1 " while ($str =~ /\w+=(\w+\{.*?\})|\w+=(\w+)/g);'

In Javascript, check here: https://regex101.com/r/wD0dL9/1. You can print group2 and group1 for desired result.

Kamal Nayan
  • 1,890
  • 21
  • 34
  • Thanks, could you give me a regex which only match the sing '=' (but not the equal in the field sourceId!) ? – Chris Nov 24 '15 at 15:54
  • Will string pattern remain always same? I mean, amongst `key=value`, will `key` be always same? i.e. Is this your string? `Objet[id=XXX,name=XXX,type=XXX,source=XXX{id=XXX,version=XXX},linked=XXX]` where XXX is a varible. – Kamal Nayan Nov 24 '15 at 19:11
0

try this

var regexp = /[a-zA-Z]+=(\w+{*(?:[a-zA-Z]+=*[\w=,]*)?}*),*/g;

demo : https://regex101.com/r/mM3dP2/3

MATCH 1: 100

MATCH 2: car

MATCH 3: grey

MATCH 4: sourceId{id=12,version=12}

MATCH 5: true

badboyunited
  • 184
  • 1
  • 6
  • Thanks, could you give me a regex which only match the sing '=' (but not the equal in the field sourceId!) ? – Chris Nov 24 '15 at 15:54