简体   繁体   English

正则表达式以匹配单个字符

[英]Regex to match a single character

我想知道是否存在可以匹配字符串并在字符串中搜索“ =”的正则表达式。

Yes, but why? 是的,但是为什么? I simple string search for "=" is usually what you want (see String.IndexOf ). 我通常只需要简单的字符串搜索“ =”(请参阅String.IndexOf )。 Doing a search for "=" using a regex means just using "=" as the regex, nothing special. 使用正则表达式搜索 “ =”意味着仅将“ =”用作正则表达式,没什么特别的。

If you want to match rather than search you can use the regex .*=.* 如果要匹配而不是搜索 ,可以使用正则表达式.*=.*

Is this what you wanted or am I missing something? 这是您想要的还是我错过了什么?

/[=]+/ / [=] + /

That will match if there is an = character one or more times anywhere in the string. 如果在字符串中的任意位置多次出现=字符,则将匹配。

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

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