October 1st, 2013, 11:42 AM
Replacing character in middle of string
I have a series of alphanumeric strings in the following format:
where the trailing alpha character may actually be one to three characters in lenght. The problem is that instead of a space between the two portions of the string, sometimes a / or - (or no space at all) has been inserted. How can I replace those characters with a space, or insert a space if none exists?
I've come up with the following, but it doesn't work. Suggestions?
October 1st, 2013, 12:01 PM
Your regexp should catch two or three groups separately. You are trying to catch the whole and it is not clear what you will do with it later.
"$1 $2$3" or "\1 \2\3"
depending on your language
October 2nd, 2013, 12:16 PM
You could also simplify and just accept ANYTHING before the #
And replace it with:
Now how you get $1 and $2 are up to you.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.