Search and Replace

Results 1 to 2 of 2

Thread: Search and Replace

  1. #1
    Join Date
    Dec 1969

    Default Search and Replace

    I&#039;m searching and replacing a string (Actually an SQL statement) for occurances of "[ENTER EXT NO:]" (without quotes) and replacing with "302".<BR>This is being done in perl and my code is currently...<BR>$find = "[ENTER EXT NO:]";<BR>$replace = "302";<BR>$sqlStatement =~ s/$find/$replace/g;<BR><BR>Of course this doesn&#039;t work as it replaces any of the characters between the []&#039;s that are in the sql string with 302.<BR>I tried escaping the []&#039;s but that didn&#039;t seem to work.<BR><BR>What am i doing wrong?<BR><BR>thanx in advance

  2. #2
    Join Date
    Dec 1969

    Default RE: Search and Replace

    The characters "[" and "]" denote a character class, and try to match any character in them (OR operation). You need to escape these characters if you want to actully match them:<BR><BR>$find = "[ENTER EXT NO:]";

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts