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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -