ruby - Regex that matches a pattern but does not match ":" -


i have regex looks types of hostnames like: .*-.*(nmtg)*|.*(\.nms). how modify not match: 11.22:33:44:55-66?

should match:

cs25-admin.nmtg.company.com  cs25-admin 

but should not match:

11.22:33:44:55-66 

two basic ways:

  • you can replace "match anything" . "match except colon" [^:] everywhere

  • you can prepend expression "no colons here end of string" (?!.*:)

edit signus said, regexp non-specific , open-ended; match more think. example, "----thricenmtgnmtgnmtg" full match, , "(-_-)". better policy , easier specify want, rather go listing exceptions. regexps suggested signus example.

they still match within strings: "dont match this: example.com" still match "example.com" part. if want, cool. if not, want anchor start , end of string, surrounding regexp /^.....$/.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -