-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.

3
  • Edit your question and include the regex you use. Also add examples of input and desired output. Commented Sep 21, 2022 at 22:14
  • 1
    Is this What you want? /([^\[\]\s]+)\[([^\[\s\]]+)\]/g - regex101.com/r/KsaJ2G/1 Commented Sep 21, 2022 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? Commented Sep 21, 2022 at 22:40

1 Answer 1

-2

Does this work for you?

^(?!\s*$).+

Sign up to request clarification or add additional context in comments.

1 Comment

How is this an answer to the question?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.