简体   繁体   English

正则表达式语法检查前缀和后缀

[英]Regex syntax to check prefixes and suffixes

I'm building some regex expressions to match naming conventions in Sigasi Studio (which uses Java syntax for regex). 我正在构建一些正则表达式表达式以匹配Sigasi Studio(正则表达式使用Java语法)中的命名约定。 For example, a port name must end in _i or _o - eg my_input_port_i 例如,端口名称必须以_i或_o结尾-例如my_input_port_i

I tried using the txt2re generator, however instead of a simple expression it generated code . 我尝试使用txt2re发生器,然而的代替简单的表达它生成的代码

Looking at regex syntax, it seems that the "$" character (end of line) and the "|" 查看正则表达式语法,似乎“ $”字符(行尾)和“ |” symbol (OR) could be helpful - something like $_i|_o but after testing with regex101.com no matches are found. 符号(OR)可能会有所帮助-类似于$_i|_o但在使用regex101.com进行测试后,未找到匹配项。

Naming convention dialog: 命名约定对话框:

Sigasi Studio命名约定

The $ means end of the string, but you use it at the beginning. $表示字符串的结尾,但是您可以在开头使用它。

Maybe you are looking for this at the end of the string, which uses an underscore _ , then a character class to match i or o and then matches the end of the string $ 也许您要在字符串的末尾寻找它,它使用下划线_ ,然后是一个字符类来匹配io ,然后匹配字符串$的末尾

_[io]$

In Sigasi Studio the entire name should match. 在Sigasi Studio中,整个名称应匹配。 So your are looking for: 因此,您正在寻找:

.*_[io]

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

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