tanstaafl
tanstaafl

Reputation: 39

Regexp to strip characters after URL in emacs

I have a .org file with lines of this sort:

*  
http://en.wikipedia.org/wiki/Qibla Qibla - Wikipedia, the free

as you can see, an asterisk, followed by newline, followed by URL, followed by one space, and then some extraneous useless text that i want to get rid of.

i would like to format this file to this structure:

*  
http://en.wikipedia.org/wiki/Qibla 

or, strip all the characters after the end of the URL while maintaining the rest of the structure.

how can i do this in emacs?

Upvotes: 2

Views: 215

Answers (1)

Luke Girvin
Luke Girvin

Reputation: 13442

Assuming you're doing this interactively with query-replace-regexp, try using this regex to string the junk off the end of the URLS:

^\(http[^ ]+\).*$

Replacement:

\1

You can get rid of the asterisks easily enough, use this regex and replace with nothing:

*^J

Use control-Q followed by control-J to enter the newline.

Edit: Or, to do it in one, replace

*^J\(http[^ ]+\) .*^J

With

\1^J

Where ^J is a literal newline inserted by typing control-Q followed by control-J.

Upvotes: 3

Related Questions