in reply to regex replace problem

the problem is that sometimes the words can have "(" such as tbgl_translate(...)
Does that mean that "tbgl_translate(" needs to be turned into "translate(_gl"? If not, that is, if the '(' is totally irrelevant, what's the problem here? In that case,
s/tbgl_(\pL+)/${1}_gl/g;
ought to do it.

Replies are listed 'Best First'.
Re^2: regex replace problem
by Anonymous Monk on Nov 18, 2010 at 14:45 UTC
    thank you Fisher and JavaFan ,i mean such as tbgl_translate(...) ---> translate_gl(...)
    your code works with many words,sample of that converted words inside htm files such as:
    href="SetMaterialSpecular_gl.htm">SetMaterialSpecular_gl
    CLASS="f_Code_Keyword">SetMaterialSpecular_gl
    but i have found that some words does not converted, it is in htm files not text , the not converted words like this inside the htm files:
    CLASS="f_Code_Keyword">TBGL_SetMaterialDiffuse( hMaterial, R, G, B )
    i want to replace TBGL_SetMaterialDiffuse(...) by
    SetMaterialDiffuse_gl(...)
    and so on for other words
    my code until now using javaFan regex:
    $file = "TBGL_SetMaterialDiffuse.htm"; open(FILE, $file) || die $!; $txt = do { local $/; <FILE> }; close FILE; $txt =~ s/tbgl_(\pL+)/${1}_gl/g; open FILE, ">output.htm" or die $!; print FILE $txt; close FILE;
    thanks
      See, that's what you get from not specifying your problem, and just giving an example that doesn't cover all the cases. You got an answer to your described problem, and now you have to come back with "well, really, the problem I described wasn't really the problem I'm trying to solve. In fact, this is the problem....".

      Use /i. For details, RTFM.

      add case-insensitive option.
      s/tbgl_([^ \t(_]+)/$1_gl/gi;
      and again, perldoc perlretut
        thank you fisher, your regex corrected some words but failed with wich JavaFan regex succeeded, this is my fault to not specify complete description; one of the reasons is that i can't post htm files, so if there is no harm to post a link to the file, i appreciate your patience [http://rapidshare.com/files/431638977/TBGL_SetMaterialDiffuse.htm]