Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Regex within a column loop formula

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 22, 2016 12:39 PM
(7779 views)

Trying in vain to have theis column formula execute correctly

For( i = 0, i < 10, i++,

Regex( :Source, :Words to Remove*, "", global replace )*

);

Ten words to remove from the source column and replaced with a null.

All help is appreciated

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

VinKane , a point of interest....since column formulas implicitly loop over all rows in a table, I've often used a little trick when I want to script JSL in a column formula. So you in your case, the column formula would look something like this:

PDB

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Regex within a column loop formula

The for loop needs to start at 1. the regex function needs to work with a JSL variable, it can't use the column. You might want to use a table variable to hold the list of words to delete rather than keeping them in a column. the JSL could be a lot simpler...see second example.

**example 1**

New Table( "Untitled 1", Add Rows( 10 ), New Column( "words to remove", Character, "Nominal",

Set Values(

{"aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj"}

)

),

New Column( "source", Character, "Nominal",

Set Values(

{"the aaa is bbb and bbb ccc", "a aaa b bbb c ccc ccc", "b bbb c ccc", "",

"", "", "", "", "", ""}

)

),

New Column( "redacted", Character, "Nominal",

** Formula(**

** x = :source;**

** For( i = 1, i <= 10, i++,**

** x = Regex( x, :words to remove , "", GLOBALREPLACE ),**

** );**

** x;**

** )**

)

);

**example 2**

New Table( "Untitled 2", Add Rows( 10 ),

New Table Variable( "redactionlist", "aaa|bbb|ccc|ddd|eee|fff|ggg|hhh|iii|jjj" ),

New Column( "source", Character, "Nominal",

Set Values(

{"the aaa is bbb and bbb ccc", "a aaa b bbb c ccc ccc",

"fred iii ralph bbb bbb", "a aaa b bbb", "", "", "", "", "", ""}

)

),

New Column( "redacted", Character, "Nominal",

Formula( Regex( :source, :redactionlist, "", GLOBALREPLACE ) )

)

)

Craige

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Regex within a column loop formula

!Thanks, works like a charm

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

VinKane , a point of interest....since column formulas implicitly loop over all rows in a table, I've often used a little trick when I want to script JSL in a column formula. So you in your case, the column formula would look something like this:

PDB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Regex within a column loop formula

Great suggestion and hint. As a newbee I'm trying to absorb all of this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Regex within a column loop formula

VinKane, my pleasure. I should add that this method is useful for relatively simple scripts/formula. As requirements grow, you eventually are better off doing everything in pure JSL, as column formulas can get a bit tedious to edit/maintain.

PDB