-2

Im trying to make preg_match_all regex that will work in next order. Group 1 to match "Example", Group 2 to match "[string]", Group 3 to match whitespace and "Number" and Group 4 to match "[int]". If the string is empty the regex should be false.

$string = Example[string] Number[int]

I have tried something with this https://regex101.com/r/MdWNCT/1, but no luck so far. Can anyone suggest me what to do?

Thank you.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Sinisa
  • 82
  • 1
  • 4
  • Edit your question and include the regex you use. Also add examples of input and desired output. – Poul Bak Sep 21 '22 at 22:14
  • 1
    Is this What you want? `/([^\[\]\s]+)\[([^\[\s\]]+)\]/g` - https://regex101.com/r/KsaJ2G/1 – Poul Bak Sep 21 '22 at 22:24
  • 1
    Your question is a bit too focused on your own solution to a problem, without actually presenting the problem itself. You probably get data from somewhere and you want to convert it to something else. Some examples of that data, and what it should become, would be nice. You tried to write a regex to solve your problem, but there may be other solutions. Perhaps even solutions everybody, including you, can understand? – KIKO Software Sep 21 '22 at 22:40

1 Answers1

-2

Does this work for you?

^(?!\s*$).+

KiraHoneybee
  • 495
  • 3
  • 12