0

I have values in my query that looks like the following: Decrease with an active address (2) or Unsecured task (100) etc.

The value within the parentheses varies, it can be one, two, three digits or more because this is a count value.

I just need to get the description not the parentheses nor the value. So what I need is just:

Decrease with an active address
Unsecured task

etc.

How can I get rid of the opening (, the numeric value and the closing )?

In ColdFusion 8?

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
user1557856
  • 163
  • 2
  • 12
  • 1
    With `reReplace()`. Or, if the stuff you want is always at the end, a combination of `left()` and `find()` will work. – Dan Bracuk Dec 20 '16 at 14:08

1 Answers1

2

As Dan mentioned in the comments, one option is using reReplace() with the appropriate expression to remove any text within parenthesis:

<cfscript>
    origText = "Decrease with an active address (2)";
    newText = reReplaceNoCase(origText, "\([^)]*\)", "", "all");
    writeDump( newText );
</cfscript>

Update:

As Alex mentioned in the comments, if you just want to "cut" the string, and grab the part before the parenthesis, try something like this:

<cfscript>
    origText = "Decrease with an active address (2) plus more text after the parenthesis";
    newText = reReplaceNoCase(origText, "\([0-9]*\).*$", "", "all");
    writeOutput("<br>"& newText );
</cfscript>
Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103
  • 1
    And if you only want to remove trailing parenthesis with numbers (as described in the question), use `\([0-9]*\)$` as the second parameter in the `reReplaceNoCase`. – Alex Dec 21 '16 at 23:22
  • @Alex - That is a good point. I read it as "remove it", but looking over the title, your suggestion is probably closer to the mark. – Leigh Dec 23 '16 at 12:15