1

I need to cut all css and js links from page, now Im using that regex:

([^ ()]*\.(?:css|js)\b)

Its works fine but its also cuts some links like:

href="stylesheets/{asfas}asf{,,.,sfasfas]F{asfas]fAS/MyFontsWebfontsKit.css

What I need to add to my regex to exclude that invalid links. I think I need exclude chars like '{},.' from regex matcher?

Im using JAVA Pattern/Macther to compile my regex.

Pls dont suggest me usage of html parsers(like Jsoup and etc).

update1:enter image description here

2
  • it's work fine. find() and group() give me an expected result Commented Aug 5, 2015 at 13:02
  • mm, I want to ignore links like 'href="stylesheets/{asfas}asf{,,.,sfasfas]F{asfas]fAS/MyFontsWebfontsKit.css', but now I grab them, pls see my update Commented Aug 5, 2015 at 13:03

1 Answer 1

2

Try with regex like this:

(?<==)([^ (){},]*?\.(?:css|js)\b)

DEMO

or:

(?<=\s)([^ (){},]*?\.(?:css|js)\b)

if you want also to grab href/src.

Sign up to request clarification or add additional context in comments.

1 Comment

@MeetJoeBlack I updated answer, what you think about new one?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.