Wednesday, 15 June 2011

css - Do not match URLs not works -



css - Do not match URLs not works -

i have css file, , extract urls in regex editor, replacing other character in css file empty characterd.

the css file, looks that:

@font-face { font-family: 'font_name'; src: url('http://my-site.ext/path/to/font/proximanova-light-webfont.eot'); src: url('http://my-site.ext/path/to/font/proximanova-light-webfont.eot?#iefix') format('embedded-opentype'),url('http://my-site.ext/path/to/font/proximanova-light-webfont.woff') format('woff'),url('http://my-site.ext/path/to/font/proximanova-light-webfont.ttf') format('truetype'); font-weight: normal; font-style: normal; }

and utilize next regex replace rest of file conten:

(?!(http[^\']+)).

but doesn't work.

the final result similar this:

http://my-site.ext/path/to/font/proximanova-light-webfont.eot http://my-site.ext/path/to/font/proximanova-light-webfont.eot?#iefix http://my-site.ext/path/to/font/proximanova-light-webfont.woff http://my-site.ext/path/to/font/proximanova-light-webfont.ttf

is there wrong pattern ?

here solution work in regex101, , maybe other online tools.

use regex (i escaped forwards slashes regex101):

search:

http[^\']+(*skip)(*f)|.

replace: empty string

in the demo, @ bottom pane (the substitutions). copy, paste, , have links.

how works

the left side of alternation | matches finish urlsthen deliberately fails, after engine skips next position in string. right side matches 1 single character, replaced empty string. may sound laborious, that's efficient way know given specs.

if want leave spaces , newlines, utilize instead:

http[^\']+(*skip)(*f)|\s

css regex

No comments:

Post a Comment