regex - Regular Expression negative lookahead to prevent the last character from being a hyphen -



regex - Regular Expression negative lookahead to prevent the last character from being a hyphen -

i'm trying capture word or multiple words between 2 , 30 characters. these characters can contain ., ', or -. regular look accomplishes this.

[a-za-z.'-]{2,30}

however 1 caveat need create sure lastly character not hyphen, attempts @ negative lookahead seems overruled fact first match allows hyphens.

i'd grateful if has solution solve problem in 1 regular expression.

you can utilize following.

[a-za-z.'-]{1,29}[a-za-z.']

explanation:

[a-za-z.'-]{1,29} # character of: 'a' 'z', 'a' 'z', # '.', ''', '-' (between 1 , 29 times) [a-za-z.'] # character of: 'a' 'z', 'a' 'z', '.', '''

regex

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -