Web Analytics Made Easy -
StatCounter Combining Regular Expressions - CodingForum

Announcement

Collapse
No announcement yet.

Combining Regular Expressions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Combining Regular Expressions

    EDIT: How would I combine regular expressions?

    I'm having a bit of trouble with the following function:
    Code:
    function filterFriends(inp) {
    	var mid = inp;
    	for(ccc = 0; ccc <= len - 1; ccc++) {
    		var reg = new Array(new RegExp("( )" + longN[ccc] + "( |,|.)", 'g'), new RegExp("( )" + shortN[ccc] + "( |,|.)", 'g'));
    		mid = mid.replace(reg[0], "\$1<span class=\"hide\">" + replN[ccc] + "</span>\$3");
    		mid = mid.replace(reg[1], "\$1<span class=\"hide\">" + replN[ccc] + "</span>\$3");
    	}
    	return mid;
    }
    I've created a similar function in PHP, with multiple input variables for the regular expression in preg_replace without any trouble. Why doesn't this function replace like the following PHP function?:
    PHP Code:
        function filterFriends($input) {
            
    $mid $input;
            for(
    $ccc 0$ccc <= count($this->repl) - 1$ccc++) {
                
    $mid preg_replace("#( )(" $this->long[$ccc] . ")( |,|.)#""$1<span class=\"hide\">" $this->repl[$ccc] . "</span>$3",$mid);
                
    $mid preg_replace("#( )(" $this->short[$ccc] . ")( |,|.)#""$1<span class=\"hide\">" $this->repl[$ccc] . "</span>$3"$mid);
            }
            return 
    $mid;
        } 
    Last edited by Kenji Miyamoto; Aug 2, 2005, 02:52 AM.
Working...
X