Python Regex in matching multiple formats -
i trying match criteria in sentence. come regex pattern, unfortunately though matching still not matching others. in sentence, need keep alphanumeric string while keeping strings have "-" inbetween , " ' " apostrophe. example
- hello
- hello-world
- year's
my regex is: (?=\s*|['-])([a-za-z0-9'-]+)
currently above regex matching "---" (should not correct) not matching "year's"
thank you
i think looking for:
[a-za-z0-9]+(?:[-'][a-za-z0-9]+)*
note (?=\s*|['-])
true assertion since \s*
matches empty string.
Comments
Post a Comment