简体   繁体   English

Csharp正则表达式检查第一个和最后一个字符是否为“'.-”

[英]Csharp regex check If first and last character is “ '.-”

i don't want first and last this characters “ '.-” 我不希望第一个和最后一个字符“ '.-”

this my regex 这是我的正则表达式

^(?!.*?[ '.-]{2})[\\p{L} .'-]+$ ^(?!。*?['.-] {2})[\\ p {L} .'-] + $

Example

  • "Test" match
  • ".Test" no match
  • "Test " no match
  • "'Test" no match
  • "'Test'" no match
  • ".Test." no match
  • " Test " no match

I solved the problem. 我解决了问题。

I add this characters [^ '.-] 我添加此字符[^'.-]

Regex final state 正则表达式最终状态

^[^ '.-](?!.*?[ '.-]{2})[\p{L} .'-]+[^ '.-]$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM