I am writing a regex to match string till specific word if word is in string else need to match full string. and match result should be group 1. here word is: -my-word
mylaptop-my-word > mylaptop (group1 match)
mylaptop > mylaptop (group1 match)
mylaptop-my-word-hello-my-word > mylaptop-my-word-hello (group1 match)
so far I tried this:
([\s\S]+)-my-word|([\s\S]+)
but it giving me
mylaptop-my-word > mylaptop (group1 match)
mylaptop > mylaptop (group2 match)
Need to be group1 match