0

I have a string:

User{self=https:example.com, name=S1234, displayName=Johny B, accountId=null, [email protected], active=true}'

I try to capture group and get Johny B in sed. I have proper regex: displayName=(.*?),

but below sed command return me all string:

's/.*displayName=\(.*?\),/\1/'
4
  • Does this answer your question? Non greedy (reluctant) regex matching in sed? Commented Sep 3, 2021 at 9:13
  • ok, when I change to 's/.*displayName=\([^/]*\),/\1/' I get substring starting ofJohny B to the end of string
    – Kucharsky
    Commented Sep 3, 2021 at 9:25
  • You have a comma to exclude, 's/.*displayName=\([^,]*\),/\1/', not a slash. Commented Sep 3, 2021 at 9:28
  • It returns incorrect substring
    – Kucharsky
    Commented Sep 3, 2021 at 9:31

1 Answer 1

1

You can try this sed

sed -E 's/.*displayName=([^,]*).*/\1/' $file

You have further strings after the match which you need to account for.

Not the answer you're looking for? Browse other questions tagged or ask your own question.