问题
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:
- http://www.petefreitag.com/item/517.cfm
- 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