regex - How to remove a specfic pattern in string or remove array elements containing a pattern -


i having difficulty figuring out how remove unwanted characters.

below sample of array data. remove occurences of "rail national" or remove elements containing string "rail national".

sample array need remove text "rail national" or part of string

if understand question correctly, remove element array contains text 'rail national' anywhere in it:

newarray = [   'adult child class',   'ticket type',   'i rail national rail nation',   'rail nationa',   'rail national',   'route'] // remove items array .filter( function(i){      return !(findnocase( i, 'rail national' ) > 0); // edit items in array } ).map( function(i){      return replacenocase( i, 'il nati', '', 'all' ); } ); 

the filter function run closure against each item in array , return item in final array if closure returns true.

http://cfdocs.org/arrayfilter

the map function return array each item potentially modified.

http://cfdocs.org/arraymap

note, didn't cf engine you're using. sample code run on lucee server.


Comments