除非它包含某个字符串,否则如何匹配所有字符串?

时间:2013-03-12 22:27:57

标签: regex google-analytics

所以我希望匹配此列表中的每个字符串,但包含产品SKU的字符串除外,它是/ s7892632< ----随机字符串。我一直试图这样做很长一段时间并且都没有成功。任何见解将不胜感激。

   /account/login?returnurl=/account/forgotpassword
    /account/login?returnurl=/account/orders
    /account/orders
    /account/updateaddress
    /account/updateemail
    /account/updaterewardscard
    /brands/havaianas
    /careers
    /Category List
    /checkout
    /checkout/addresses
    /checkout/addresses/delivery
    /checkout/addresses/deliverymethod
    /checkout/affilinetbasket
    /checkout/anonymous
    /checkout/confirmation
    /checkout/express
    /checkout/login
    /checkout/login?returnurl=/checkout/addresses
    /checkout/null
    /checkout/payment
    /checkout/paypal
    /checkout/quickshop/
    /checkout/verify
    /click-and-collect
    /click-and-collect/click-and-collect-overview
    /corporate/about-matalan
    /corporate/careers
    /corporate/cookies
    /corporate/history
    /customer-services/accessibility
    /customer-services/contact
    /customer-services/customer-services-home
    /customer-services/delivery
    /customer-services/faq
    /customer-services/fitting-room
    /customer-services/here-to-help
    /customer-services/size-guides
    /delivery
    /events/mothers-day
    /events/mothers-day/s2516241/tassle-detail-slouch-bag
    /events/mothers-day/s2518752/waxed-jacket
    /events/mothers-day/s2519237/fabric-buckle-tote-bag
    /events/mothers-day/s2521182/heart-print-nightie
    /events/mothers-day/s2521184/heart-print-dressing-gown
    /events/mothers-day/s2521185/heart-print-pyjama-set
    /events/mothers-day/s2521679/structured-tote-bag
    /events/mothers-day/s2522143/chiffon-print-dress
    /events/mothers-day/s2522347/butterfly-enamel-bowl-32cm-x-8cm
    /events/mothers-day/s2526013/animal-print-jersey-blazer
    /events/mothers-day/s2527624/croc-tote-bag
    /events/mothers-day/s2529731/shift-dress
    /events/mothers-day?page=1&size=120&cols=4&sort=&id=/events/mothers-day&priceRange[min]=2&priceRange[max]=59
    /events/mothers-day?page=2&size=120&cols=4&sort=&id=/events/mothers-day&priceRange[min]=2&priceRange[max]=59
    /events/mothers-day?page=2&size=36&cols=4&sort=&id=/events/mothers-day&priceRange[min]=2&priceRange[max]=59
    /events/mothers-day?page=3&size=36&cols=4&sort=&id=/events/mothers-day&priceRange[min]=2&priceRange[max]=59

3 个答案:

答案 0 :(得分:1)

以下内容应该有效:

^(?!.*/s\d{7}/).*

示例:http://regexr.com?343nf

这假设您将每个字符串作为列表中的单独元素。如果这实际上是将一个大字符串与多行匹配,则可以使用相同的正则表达式,但您可能需要根据所使用的工具启用全局和多行选项(并确保禁用dotall / singleline)。

答案 1 :(得分:0)

试试这个:

boolean noSku = !line.matches(".*/s\\d{5,}.*");

这使用{5,},它允许SKU中任意数量的数字大于4(为您提供匹配的灵活性)。您可以将数字更改为任何适合的数字。

答案 2 :(得分:0)

这匹配没有代码的行....

^((?!s\d{7}).)*$