-1

I need to get

first="john"
second="doe"

and

firstz="johnz"
secondz="doez"

from this text:

any text here [link first="john" second="doe"] anytexthere [link firstz="johnz" secondz="doez"]

The pattern need to get the [link in the start, and the ] in the end, and can have multiples properties inside...

[link first="john" second="doe"] ✅ -> first="john", second="doe"
[lin first="john" second="doe" ❌
[link first="john second="doe"] ❌
[linksecond="doe"] ❌

Obs: "first", "john", "second", "doe" can be anything.

This is my best try: https://regex101.com/r/cJnYIF/1

\[link (\w+="\w+")\]

But this only capture the first

I've also tried with positive lookbehind, but without success https://regex101.com/r/jnk6gM/397

Someone have idea how to solve this? If possible XD

3
  • You need to use a positive lookbehind. But positive lookbehinds aren't allowed to use quantifiers, so it won't work.
    – Barmar
    Commented Apr 10, 2020 at 19:50
  • Best one for this are .NET regex and PyPi Python regex libraries where you have access to all captures of each group. In PCRE, you may use (?:\G(?!\A)|\[link)\s+(\w+)="(\w+)" Commented Apr 10, 2020 at 19:51
  • Thank you guys, GalAbre answer was a good way to solve my problem :D I think my idea of getting params as groups is not possible directly, but the @WiktorStribiżew it could have been a way if I were using these languages
    – Emanuel
    Commented Apr 10, 2020 at 20:07

1 Answer 1

0

You can use the following regex, which will match all your parameters:

\[link ((?:\w+="\w+" ?)+)\]

Then you can parse them using a split(' ') function, depending on the language you use.

1
  • 1
    This really helps, thank you! :D
    – Emanuel
    Commented Apr 10, 2020 at 19:57

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