Regular expression to split optional groups
Full string syntax is: "db:server:port" Server and port are optional, i.e. can have partial strings, such as: db or db:server Trying to use: (.*):?(.*)?:?(.*)? selects the whole string Please advise.
Give this one a shot: ([^:]*?):?([^:]*?):?([^:]*?)$ Not sure what language you're using, so it may not work. Example: http://regex101.com/r/eQ6bF0 Note on the example it's set for a global/multiline match - beware that this will match across newlines if you don't use the correct modifier.
You didn't specify a language that I can see, so there may be different specific answers, but the basic problem is that .* will match a ":" character. That means the first term will suck the entire string in. I would use ([^:]*) instead of (.*).
You can try this: ([^:]+)(?::([^:]+)(?::([^:]+))?)?
I think this is what you're looking for: (db|:server|:port) will match any and all of these: db:server:port db db:server Working example: http://regex101.com/r/rK1lI5
Test but not select with regex
Pattern to delete lines causes the whole contents of the file to be deleted in Sed
Using a regex in a conditional vs. an outright awk/sed?
Regex for a valid month
Remove everything except a certain pattern
Hubot Not Responding to regex
RegExp to find first letter of words before #
Creating Index based on another field in logstash
Bug in R's grepl? [closed]
Regular Expression Google Form only numbers in a range
MS Word VBA macro to search and replace (Regex)
Repeat capture group ignoring whitespaces
regex help in notepad++ marking embedded values and copying into a new list
uWSGI routing rule is overriding static files
How to match more than one pattern and delete a line using sed?
move pattern in file over one column if match awk