in reply to Re: Replace not working
in thread Replace not working
G and Y in the example could be any chars.
Well, in case your code is still not doing exactly what you want, and you're still wondering how to fix it, maybe it's time to provide some of the real examples that you are actually dealing with.
I have to say that the example string in the OP is probably not what you meant it to be. In this statement:
the value assigned to "$second_str" is actually:$second_str = "591[\s-~]*G-Y[\s-~]*6";
Do you really have literal strings in your data that look like that? If you really do, is there some special rule about hyphens that are inside square brackets (don't replace with space) vs. hyphens that are not inside square brackets (replace these with space)?591[s-~]*G-Y[s-~]*6
If it's just a matter of replacing all hyphens with spaces, then this will do it more efficiently:
But if you have contextual constraints (e.g. must be adjacent to letters/alphanumerics, and/or must not be within bracketed strings, or whatever), you haven't really given us any clear idea about that yet.tr/-/ /;
|
|---|