I am trying to match some criteria in my sentence. I could come up with a regex pattern, but unfortunately though some are matching but still it is not matching properly for others. In a sentence, I need to keep the alphanumeric string only while keeping those strings which have "-" inbetween and " ' " apostrophe. Example
- hello
- hello-world
- year's
my regex is: (?=\S*|['-])([a-zA-Z0-9'-]+)
currently the above regex is matching "---" (should not be correct) but not matching "year's"
Thank you