• 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 Technique in ColdFusion

New Here ,
Dec 08, 2009 Dec 08, 2009

Copy link to clipboard

Copied

I'm new to Coldfusion and I've never really used regular expressions before.  How would I write a ColdFusion function (or just a conditional statement) to check if a form variable is a match for an IP network (44.42.94.0/18)?

I'm just basically looking to see if the backslash "/" character is in the string.

TOPICS
Advanced techniques

Views

508

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
Valorous Hero ,
Dec 08, 2009 Dec 08, 2009

Copy link to clipboard

Copied

newguy1300 wrote:

I'm just basically looking to see if the backslash "/" character is in the string.

The simplest method for this would be <cfif find(ipstring,"/") GT 0>

A regex expression that might do what you want, completely untested would be ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}\[0-9]{1,???}  I'm not sure how many digits you want to allow after the slash.  Replace the question marks with that number.

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 ,
Dec 09, 2009 Dec 09, 2009

Copy link to clipboard

Copied

The simplest method for this would be <cfif find(ipstring,"/") GT 0>

I think using find() is a better solution that trying to concoct a regex for this, but... you might want to check the order of parameters for find()...

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_21.html#5177400

--

Adam

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
Valorous Hero ,
Dec 09, 2009 Dec 09, 2009

Copy link to clipboard

Copied

It is always good to check the documentation.

But I do find it a bit annoying that the ColdFusion string functions seem to be some of the most inconsitant in what order the comon paramters come.

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
Engaged ,
Dec 16, 2009 Dec 16, 2009

Copy link to clipboard

Copied

LATEST

There are actually plenty of well-developed regular expression strings available on the Internet, which you can simply "copy and use."  You don't have to spend too much time figuring-out the correct pattern of chicken scratches.

It's not quite as convenient as saying  "use Regexp::Common::URL;" but one cannot have everything in "less-enlightened" languages like CF...

You do need to understand them, however.  When you look at the string given in a previous reply, you do need to understand the meaning of all those symbols, and you need to practice the art of being able to cook them up extemporaneously.

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