How do I match a string that does not contain X with ColdFusion regular expressions?

泪湿孤枕 提交于 2019-12-12 01:32:53

问题


I asked this question earlier, but it got a negative vote, so I'm rewording it. I have:

<cfset myExpression = "X">
#REFind(myExpression,myString)#

I need to change myExpression so that it returns a value other than zero if there is NOT an X in myString, and a 0 if there is an X in myString.


回答1:


<cfset string = "abc" />  
<cfoutput>#refind( "^[^X]+$" , string )#</cfoutput> // 1 

<cfset string = "abcX" /> 
<cfoutput>#refind( "^[^X]+$" , string )#</cfoutput> // 0



回答2:


please check the following links:

  1. http://www.petefreitag.com/item/517.cfm
  2. http://www.adobe.com/livedocs/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/regexp3.htm

hope these will help you.




回答3:


I am building a validation table

Well, the first thing to check is that you're not re-inventing the wheel - the isValid function can validate a variety of types (creditcard,email,zipcode,etc).

It also provides a way to match against a regex pattern, like this:

<cfif isValid('regex',String,RegexPattern) >

Something to be aware of: the documentation for isValid claims that it uses JavaScript regex, which (if true) is different to the default Apache ORO regex that CF uses for everything else.

For the direct regex version of what you were doing (which does use Apache ORO), you would use:

<cfif refind(RegexPattern,String) >


It's not clear what you're on about with your returnValue bit, though if you're returning a boolean from a function, ditch the cfif and just do one of these instead:

<cfreturn isValid('regex',String,RegexPattern) />

<cfreturn refind(RegexPattern,String) />



回答4:


if your expression is always a character or set of characters then you want

<cfset myExpression ="[^X]">



来源:https://stackoverflow.com/questions/3409065/how-do-i-match-a-string-that-does-not-contain-x-with-coldfusion-regular-expressi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!