Use of Java regular expression, doesn't match *.jpg or *.gif

MauTOz

[EDITED] I'm using Java Regular expression and I don't want match some files.

I'm trying:

String regexp = "https?:://[[\\S]&&[^\"]]+(?!.*(.ico|.jpg|.css)"

I have a list with links from many websites, the links are: *.html, *.asp, *.jpg, *gif. I want use java regular expression to match everything but *.jpg, *gif, *ico.

Can someone give an idea?

Sorry, I'm not fluent in English. Hope you can understand me. Thanks!!!

CodeJockNYC

Here is an example of program small program that will parse match links for a website but will exclude specific extensions.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexTest {

    public static void main(String[] args) {
        String regex = "(https?://[\\S^\"]+(?<!\\.ico|\\.jpg|\\.css))[\\s\"]";

        String test_string = "http://www.regular-   expressions.info/shorthand.html "
                + "http://www.regular-expressions.info/shorthand.html "
                + "http://www.regular-expressions.info/shorthand.css "                          
                + "http://www.regular-expressions.info/shorthand.ico "
                + "http://www.regular-expressions.info/shorthand.jpg "
                + "http://www.regular-expressions.info/shorthand.htm "
                + "http://www.regular-expressions.info/shorthand.jsp "
                + "http://www.regular-expressions.info/ ";


        Pattern pattern = Pattern.compile(regex);
        Matcher m = pattern.matcher(test_string);
        while (m.find()) {
            System.out.printf("Match: '%s'\n",  m.group(1));
        }
    }

}

Here are the results:

Match: 'http://www.regular-expressions.info/shorthand.html'
Match: 'http://www.regular-expressions.info/shorthand.html'
Match: 'http://www.regular-expressions.info/shorthand.htm'
Match: 'http://www.regular-expressions.info/shorthand.jsp'
Match: 'http://www.regular-expressions.info/'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java Regular Expression doesn't find a match

From Dev

Why my regular expression doesn't match this?

From Dev

Regular Expression doesn't Match with string

From Dev

Use regular expression to match "≈"

From Dev

Java: Regular expression doesn't work as expected

From Java

Regular expression to match a line that doesn't contain a word

From Dev

Regular expression for word that doesn't match a list of words

From Dev

Regular expression with named subpattern doesn't see the best match

From Dev

Match line that doesn't end with >\s* using regular expression

From Dev

Regular Expression to match string which doesn't contain substring

From Dev

Regular expression to match text that "doesn't" contain a word?

From Dev

Why doesn't regular expression alternation (A|B) match as per doc?

From Dev

Why regular expression doesn't match input with sed command

From Dev

Java regular expression boundary match?

From Dev

Regular expression in java to match XML

From Dev

Partial match for regular expression in Java

From Dev

Doesn't work regular expression

From Dev

Regular expression doesn't work

From Dev

Doesn't work regular expression

From Dev

Java Regular Expression Matcher doesn't find all possible matches

From Dev

Java Regular Expression Matcher doesn't find all possible matches

From Java

Java regular expression to match valid Java identifiers

From Dev

Use regular expression to match a string in Notepad++

From Dev

Python regular expression to match IPV4 address doesn't work

From Dev

Regular Expression Match Doesn't Start With, Contain, Or End With Space And Not Empty String

From Dev

Python regular expression to match IPV4 address doesn't work

From Dev

Can't match string using regular expression with "?"

From Dev

Regular Expression: if, else if to use in Java

From Java

Java regular expression returning false on match

Related Related

  1. 1

    Java Regular Expression doesn't find a match

  2. 2

    Why my regular expression doesn't match this?

  3. 3

    Regular Expression doesn't Match with string

  4. 4

    Use regular expression to match "≈"

  5. 5

    Java: Regular expression doesn't work as expected

  6. 6

    Regular expression to match a line that doesn't contain a word

  7. 7

    Regular expression for word that doesn't match a list of words

  8. 8

    Regular expression with named subpattern doesn't see the best match

  9. 9

    Match line that doesn't end with >\s* using regular expression

  10. 10

    Regular Expression to match string which doesn't contain substring

  11. 11

    Regular expression to match text that "doesn't" contain a word?

  12. 12

    Why doesn't regular expression alternation (A|B) match as per doc?

  13. 13

    Why regular expression doesn't match input with sed command

  14. 14

    Java regular expression boundary match?

  15. 15

    Regular expression in java to match XML

  16. 16

    Partial match for regular expression in Java

  17. 17

    Doesn't work regular expression

  18. 18

    Regular expression doesn't work

  19. 19

    Doesn't work regular expression

  20. 20

    Java Regular Expression Matcher doesn't find all possible matches

  21. 21

    Java Regular Expression Matcher doesn't find all possible matches

  22. 22

    Java regular expression to match valid Java identifiers

  23. 23

    Use regular expression to match a string in Notepad++

  24. 24

    Python regular expression to match IPV4 address doesn't work

  25. 25

    Regular Expression Match Doesn't Start With, Contain, Or End With Space And Not Empty String

  26. 26

    Python regular expression to match IPV4 address doesn't work

  27. 27

    Can't match string using regular expression with "?"

  28. 28

    Regular Expression: if, else if to use in Java

  29. 29

    Java regular expression returning false on match

HotTag

Archive