I want to get this results (from -> to)
# use string length limit = 3
1 {2 3} -> 1 # the string between the {} must be whole
1 2 3 -> 1 2
1 23 -> 1
{1} -> {1}
{1 2} -> empty
123456 -> 123 # if there is no spaces, cut string by symbols (except {*} expressions). Not necessarily but it would be cool
# one more example. Use string length limit = 5
{1} 2 -> {1} 2
123 45 -> 123
123 4 -> 123 4
Is there a way to do this using PHP with one regex expression?
Length limit may be dynamic.
Similar question - Get first 100 characters from string, respecting full words (but my question requires full contain {*} expressions )
I tried: ^(.{1,3})({.*}|\s|$)