Replace between two characters in VI - replace

I have a file like this:
14:rs546195859:105415517:C:T:AHNAK2
19:rs200396606:7676575:G:A:CAMSAP3
...
I need to replace the rs* between the first two : with "." in VI.
How can I achieve this?
Thanks!!

Something like this should find and replace that pattern
:%s/:rs[^:]\+:/:.:/g

Related

How to match strings using Regex

I have this:
https://lh5.ggpht.com/-05ne7Y9Dlog/Xyiy88vo_gI/AAAAAAAAHV4/EwmlTE7FiDonC_lh6Z-UrAtZz_39zRo3QCLcBGAsYHQ/w400-h270/1.png
https://lh5.ggpht.com/-x5hXwqku5es/XyjF5x9Q_jI/AAAAAAAAHWw/F4ayROJynrwKd1H699eu4Ji0yEfayS_RwCLcBGAsYHQ/w171-h200/3.png
https://lh5.ggpht.com/-lWHlL8F0FJo/XyiuolbZWwI/AAAAAAAAHVA/-fOvqyq2rTUxZI2Vxg0op5NwZjg-Apz9QCLcBGAsYHQ/w856-h1000/3.png
And i want to match strings like "w400-h270", "w171-h200", "w856-h1000"... Anyone can help me to solve this. Thanks.
(w\d+-h\d+)
Then extract the contents by group(1)

Remove spaces in string under quotation in Notepad++ using RegEx

Suppose I have these strings:
'akshay ' ,
' ankur'
I want to remove trailing and leading spaces present under quotation mark like this:
'akshay',
'ankur'
How can I achieve this in Notepad++ using RegEX?
Use this to find: '(\s*)(.*?)(\s*)' and this to replace: '\2'.
Find this regexp: (^')\s+(\w+)\s*(')|(^')\s*(\w+)\s+(')
Replace with : \1\2\3\4\5\6
Like this:
All the RegExp given above solve my problem in a better way. I appreciate to all who helped me to solve this problem. Thank you everyone.
Here i am going to add a RegExp given below which can be used to count total number of spaces inside single quotation. It can be used to remove all spaces also.
Find--> \s(?!(?:[^']*'[^']*')*[^']*$) and ReplaceWith-->Nothing to do(leave blank) then click 'ReplaceAll'.

Notepad++ Remove text before characters but have 2 same characters on every line

Hi masters i need your help on Notepad++ RregExpp
i have text like this :
01:example#mail.com:test
need to convert like this :
example#mail.com:test
Thank you in advance if you help me.
Use expression ^... and replace it with empty string or better with \n like following (and remove the first two characters):
Here is a way to go:
Ctrl+H
Find what: ^[^:]+:(.+)
Replace with: $1
Replace all
Make sure to have checked Regular expresion but NOT . matches newline

how to escape metacharacter like "/" and "." in regex?

Original:
src="this/text/is/not/needed/me/at/all/<filename>.jpg"
src="this/is/another/text/that/is//also/not/required/<filename>.jpg"
My desired output should be:
src="IMAGES/<filename>.jpg"
I want to remove the path of *.jpg file in src="" and want src="images/*.jpg" using regex in notepad++.
How can I do that?
Find what: src=".*/(.*\.jpg)"
Replace with: src="images/$1"
You can try to replace src=".*?\/([^\/]*?\.jpg)" with src="images/$1".
You can use this regex to find -
(src=").*(\/.*\..*")
And replace with -
$1IMAGES$2
A single REPLACE ALL should work.
Replace src=".*/([^/]+.jpg)" with src="images/$1"

Regex for search and replace in vim

I have a file which has multiple entries like this:
Abcd:abcd:*sometext*:klm:xyz/abc
Abcd:abcd:R%fs90uw:klm:xyz/abc
Now, I want to replace "klm" with "qrs" for only those lines which have the "sometext" string in the line.
How can I do this using the search and replace feature in vim?
Thanks!
:g is your friend:
:g/sometext/s/klm/qrs/g