Reputation: 1
I am trying to extract image urls from css file using a notepad++. Since all the image urls are inside of the round brackets I am thinking about regex to remove everything before ( and everything after ). Here is a text example :
text-transform:uppercase;
font-size:17px;
}
.conTxt .btnGiveAccess{
width:532px;
height:145px;
background:url(http://www.website.com/css/images/btn-give-me-access2.jpg) no-repeat center top;
margin:0 auto;
display:block;
}
.conTxt .btnGiveAccess:hover{
background:url(http://www.website.com/css/images/btn-give-me-access2.jpg) no-repeat center -145px;
}
/*#########################################*/
popup window
/*#########################################*/
/*a {
As a result I woul dlike to get the following:
http://www.website.com/css/images/btn-give-me-access2.jpg
http://www.website.com/css/images/btn-give-me-access2.jpg
I also tried the following regex to delete everything before http://
^[^http]*` Also .*((.*)).*
but it didnt work. Could anybody please help?
Upvotes: 0
Views: 3575
Reputation: 14047
For the given text the following works. Use a find text of (\A|\))([^()]*)(\(|\Z)
and replace that with \r\n
. This will leave the required text plus a few empty lines that can easily be removed, eg by menu => Edit => Line operations => Remove empty lines.
A minor variation is to use a replacement string of \1\3
. which will remove everything outside the round brackets leaving the brackets themselves and the text between them. It is then a simple job to remove all round brackets, perhaps replacing them with new lines. This could be done with a find text of [()]+
and replace string of \r\n
.
Explanation of the first regular expression. The captures are:
(\A|\))
which looks for either the start of the buffer, the \A
or a close bracket.([^()]*)
which looks for a sequence of characters that do not include round brackets.(\(|\Z)
which looks for a close bracket or the end of the buffer, the \Z
.The effect is to look for a three types of text.
(\A)([^()]*)(\(|\Z)
.(\))([^()]*)(\()
.(\))([^()]*)(\Z)
.This may not do the desired job if there are nested round brackets, but the question does not specify what should happen in such cases.
Upvotes: 1
Reputation: 6281
If none of the URLs have parens in them, you could use \((.*)\)
The difference between this and what you show above is that the outer ()
(the literal ones, not the ones that make the regex capture) are escaped using \
Upvotes: 0