I want to use regex to split some string like this @key='value' to key and value.
my regex is [^@'=]+[^'=], the output is good when the length of key and value is > 1, but sometimes when the length is only 1 char, the output is not correct.
Can anybody suggest improvements for my regex?
If you’d like to capture the key and value, you might try this:
Then you will have the key in $1 and the value in $2.
EDIT:
I think I see what you’re doing. Change your regex simply to
[^@'=]+to see the difference. However we can’t tell help you unless you tell us what language you’re using and some sample code.