• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Regular expression syntax

Explorer ,
May 15, 2012 May 15, 2012

Copy link to clipboard

Copied

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 15, 2012 May 15, 2012

Copy link to clipboard

Copied

Shouldn't this return 6? It is returning 1 for me. Is this broken or am I doing something incorrectly?? Changing this to reMatchNoCase returns an array of each lowercase letter, so that is why it returns 1, but I think that is a bug.

foo = "this Test";

writeDump(reFindNoCase("[[:upper:]]",foo));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 15, 2012 May 15, 2012

Copy link to clipboard

Copied

DUH, reFindnocase is going to find letters and ignore case! Copy/paste foils me again! Sorry!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 03, 2012 Oct 03, 2012

Copy link to clipboard

Copied

How would you negate specific characters then? In my cftextarea I don't want to allow single or double quotes. In the cftextarea tag I set validate="regular_expression" pattern="([\'\&\*\#\"]*$)" but I get an error because CF thinks I'm closing the pattern parameter before the closing ] bracket. I've tried to pass pattern as a literal by using single quotes instead and that didn't work either.

A workaround example would be greatly appreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2012 Oct 03, 2012

Copy link to clipboard

Copied

I don't know about CF RegEx, but I think in JavaScript RegEx, certain characters within [ and ] don't need to be escaped.

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 03, 2012 Oct 03, 2012

Copy link to clipboard

Copied

Thanks WolfShade. I think I'm going to try a different approach and sanitize the field on the submit page and strip the quotes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 03, 2012 Oct 03, 2012

Copy link to clipboard

Copied

First, be sure to have validate="regex" so that the tag runs your pattern, then try:

pattern="[^'\&##""\*]"

That should exclude what you're trying to exclude.

For instance, if you try <cfoutput>#reReplace("Test me withou't any quotes.", "['\&##""\*]", "", "all")#</cfoutput>, you'll get:

Test me without any quotes.

So that pattern should work (just with the addition of the ^ at the beginning, since in the textarea you're trying to validate that you've got anything BUT those characters, as far as I can tell.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 03, 2012 Oct 03, 2012

Copy link to clipboard

Copied

LATEST

JMF,

Thanks a million! I actually ended up figuring something similar. I let the form accept any character (because the email that sends info still renders those characters fine). The submission page though also writes the data to XML and submits to another application hence needing to strip the quotes (otherwise it blows up). So I just set this at the top of the submission page:

<cfset description = "#REReplace(FORM.description,"[^0-9A-Za-z\s \\\/\(\)\%\@\$\!]","","all")#">

Though I believe your solution looks a lot more elegant.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation