Professional Web Applications Themes

using regexp to substitute - problem - PERL Beginners

Hi, I am trying to substitute "TR" for "TC". But I do not want words like "AUDIT TRAIL" to be substituted. So my regexp is: if( =~ / TR / ) { s/TR/TC/g } But this is not exactly working. As i want only those instances when TR is surrounded by spaces ie not part of any other word to be substituted. The sample file i want to make the changes in is below: ---------------------------------------------------------------- if ($_ eq $AUDIT_TRAIL_FIELD) my $doc = "TR" . $pr . "Doc"; mark_urls($q->escapeHTML($fields{$AUDIT_TRAIL_FIELD})), my $page = "Edit TR $pr"; error_page("You must specify a TR number"); ...

  1. #1

    Default using regexp to substitute - problem

    Hi,
    I am trying to substitute "TR" for "TC".
    But I do not want words like "AUDIT TRAIL" to be substituted.

    So my regexp is:

    if( =~ / TR / ) {
    s/TR/TC/g
    }
    But this is not exactly working.

    As i want only those instances when TR is surrounded by spaces ie not part
    of any other word to be substituted. The sample file i want to make the
    changes in is below:
    ----------------------------------------------------------------
    if ($_ eq $AUDIT_TRAIL_FIELD)
    my $doc = "TR" . $pr . "Doc";
    mark_urls($q->escapeHTML($fields{$AUDIT_TRAIL_FIELD})),
    my $page = "Edit TR $pr";
    error_page("You must specify a TR number");
    Clone this TR for other release</b></font><br><br> ";
    print "<h1>Edit TR: $pr</h1>";
    if ( $default =~ /\s/ ) # we got multiple releases TR
    my $doc = "TR" . $pr . "Doc";
    if ( confirm ("State was changed to
    feedback, but Responsible was not
    re-assigned.\\n Click Cancel to re-assign
    Responsible, click OK to submit TR as
    is.\\n") )
    mark_urls($q->escapeHTML($fields{$AUDIT_TRAIL_FIELD})),
    my $page = 'Edit TR Results';
    error_page("You must specify a TR number");
    print "<h3>debugging -- TR edits not submitted</h3><font
    size=1><table cellpadding=\"5\" width=\"95%\">";
    error_page("Sorry, TR $pr has been modified since you started
    editing it.",
    'or "TR\'s", not "bugs".');
    Radhika Guest

  2. #2

    Default Re: using regexp to substitute - problem

    Radhika Sambamurti wrote: 

    You probably want to use the word boundary assertion:

    s/\bTR\b/TC/g;

    See "perldoc perlre".

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  3. #3

    Default Re: using regexp to substitute - problem



    Thanks! This worked.
    Radhika Guest

Similar Threads

  1. Metacharacter problem in regexp
    By Petri in forum PERL Beginners
    Replies: 6
    Last Post: March 7th, 08:46 PM
  2. regexp splitting problem
    By Brett in forum Ruby
    Replies: 4
    Last Post: December 3rd, 01:17 AM
  3. regexp problem
    By Taylor York in forum PHP Development
    Replies: 14
    Last Post: October 17th, 03:11 PM
  4. regexp problem with UTF8
    By Risto Vaarandi in forum PERL Miscellaneous
    Replies: 0
    Last Post: July 16th, 03:03 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139