Hello-Help with regular expressions
Antonio MiBoost last edited by
Hello there, ive been messing around with regular expressions feature of search and replace and i have to say im not a programmer. I feel im asking a complex thing tho :)
Have a list in a txt file formatted as above
is it possible to make them like
evidencing that what is before and after the first and second “:” can be words or numbers | what is among commas after second “:” (220.127.116.11.5) are only numbers.
I hope i’ve explained correctly what i intend to do :)
Thanks in advance!
Scott Sumner last edited by
Not so complex, hopefully there is a learning opportunity for you here! Nothing is worse than someone that repeatedly posts about regular expressions, and demonstrates with the questions that they aren’t learning, but are rather just looking for someone to write their regular expression searches for them. :-D
Search mode: Regular expression
Here’s what it does:
Find the start of a line, followed by one or more characters that are not : (and remember that as group #1), followed by a :, followed by one or more characters that are not : (and remember that as group #2, followed by a :, followed by one or more characters out to the end of the line.
Replace the found text with the contents of group #2, a :, a blank space (the \x20) and the contents of group #1.
guy038 last edited by guy038
If you are sure that the last colon, of each line of your file, is the exact location which separates the two parts, of each line, to be reversed , an other formulation could be :
\2: \1( with a space between the colon
:and the back-reference
(?-s)first part ensures that the dot special character (
.) represents a single standard character and not any End of Line character
Then the part
(.+):, look, from beginning of line (
^), for the longest non-empty range of standard characters, followed by the last colon of each line, which is stored as group 1, due to round brackets
Finally, the part
(.+), grabs all the remaining standard characters of the current line ( = all text after the last colon character ) and stores them in group 2