[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hey. I'm trying to use Regular Expressions in Vim to match

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 26
Thread images: 2

File: mre3_sm.gif (17KB, 180x236px) Image search: [Google]
mre3_sm.gif
17KB, 180x236px
Hey. I'm trying to use Regular Expressions in Vim to match all the dots followed by "gentoo" without making the dot a part of the match.

Free as in freedom.gentoo
Free as in freedom.
Free as in freedom.gentoo
Free as in freedom.gentoo
Free as in gratis.
Free as in freedom.gentoo
Free as in beer.

Is it possible to do that with regex? I've done something similar with a positive lookahead, but in this case I think I might need to use a lookbehind instead, but I can't for the life of me get it to work. Any help would be greatly apreciated.
>>
>>57091006
Match 'all of the dots'?
>>
>>57091080
No, just the dots followed by the string "gentoo".

So all ".gentoo".

However, I don't want the . to be a part of the match because I intend to remove the gentoo part.
>>
if they're always on the end:

gentoo$
>>
>>57091006
You want to do group capture. I don't use vim so I don't know how it works, but this should work:

\.(gentoo)$

Then you call upon capture group 1.
>>
>>57091165
Unfortunately this isn't gonna work, because in other parts of the data set this happens:


Free as in freedom.gentoo
Free as in Liberté.gentoo
Free as in Libre.gentoo

I'm only interested in removing the "gentoo" in the strings "Free as in freedom.gentoo".
I should have specified that in the OP.
>>
>>57091218

Does this work? It expects all your lines to either end in a period or .gentoo. https://regex101.com/r/LwdwwJ/1

([a-zA-Z0-9 ]*).(gentoo)?
>>
[^Freedom\.]gentoo$

should match Freedom.gentoo but exclude freedom. from the match
>>
>>57091218
sed "s/.gentoo//" inputfile.txt > outputfile.txt
>>
>>57091218
Can't you change the mode to multiline? $ matches the end of the line? His regex seems to match every gentoo you seem to be asking for...
>>
>>57091333
gentoo$/s in Vim matches all the gentoo, but I'm only interested in those that are at the end of the string "Free as in freedom.gentoo".

See

>>57091218
>>
>>57091309
Oh wait, forgot to include the end line decleration.

[]$ cat > testfile
Free as in freedom.gentoo
Free as in freedom.
Free as in freedom.gentoo
Free as in freedom.gentoo
Free as in gratis.
Free as in freedom.gentoo
Free as in beer.
Gentoo is life, gentoo is love. Gentoo
is freedome!.gentoo

[]$ sed 's/.gentoo$/./' testfile > newfile
[]$ cat newfile
Free as in freedom.
Free as in freedom.
Free as in freedom.
Free as in freedom.
Free as in gratis.
Free as in freedom.
Free as in beer.
Gentoo is life, gentoo is love. Gentoo
is freedome!.



Not sure how to do it inside vim, but sed is faster and easier.
>>
>>57091309
Unfortunately I have to use Vim, and that doesen't work correctly in Vim.

>>57091297
This doesen't work in Vim nor in RegExr ( a javascript regex implementation).

>>57091273
It works, but unfortunately it also matches all the .gentoo in

Free as in Liberté.gentoo
Free as in Libre.gentoo
>>
>>57091518
Reading the vim manual at http://vimregex.com/#substitute, here's my guess.

:range s/.gentoo\n/./c


You simply substitute .gentoo\n with . and it should work. The c flag is there to confirm every substitution.
>>
>>57091488
Thanks for this! Unfortunately allthough I love sed, I can't use it as it is a requirement that it either works in Vim or (preferably) a javascript implementation.
>>
>>57091557
Oh woops, should be
:range s/.gentoo\n/.\n/c


or else you'll remove all \n
>>
>>57091557
>>57091577

Thanks! But unfortunately both give me the error:

E486: Pattern not found
>>
\w+(?=\.gentoo)
>>
>>57091586
:%s/\.gentoo$/./
>>
>>57091681

When I do it (in gVim) it highlights all the .gentoo regardless of what preceeds it.
>>
>>57091750
Oh, the escape for the period was unnecessary. So it's just
:%s/.gentoo$/./
>>
>>57091750
This removes all the gentoo.

I need it to only remove the gentoo on the strings == "Free as in freedom.gentoo"
>>
>>57091775
>>57091775
:%s/Free as in freedom.gentoo$/Free as in freedom./
>>
File: fckya.gif (2MB, 348x258px) Image search: [Google]
fckya.gif
2MB, 348x258px
>>57091804
YES!! Thank you so much!
>>
In sublime
Find (\.)(gentoo)
Replace $1
>>
wow 24 posts in, umm

>>57091804
You mean
:%s/Free as in freedom\.gentoo$/Free as in freedom./


The . will select any character.
Thread posts: 26
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.