Skip to content

A Javascript library that manages mach patterns for matching urls

License

Notifications You must be signed in to change notification settings

jc3213/matchpattern.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Usage

Download

Latest

HTML

<script src="https://jc3213.github.io/matchpattern.js/matchpattern.js"></script>

TamperMonkey

// @require https://jc3213.github.io/matchpattern.js/matchpattern.js

Method

create

let pattern = MatchPattern.create("www.example.com"); // *.example.com
  • pattern
    • string
  • url
    • string
    • https://www.example.com/pathname
    • www.example.com
    • *.example.com

pattern

  • *.example.com
    • Matches www.example.com, example.com
    • Doesn't Match test-example.com, www.example.com.cn
  • example.*
    • Matches example.com, example.co.uk
    • Doesen't Match www.example.com, example-test.com
Match Pattern Target Hostname
<all-urls> All hostnames
www.university.org.eu
*.university.org.eu
*.org.eu
www.university.org.eu
doc.university.org.eu
doc.university.org.*
doc.university.*
doc.university.org.eu
192.168.1.*
192.168.*
192.*
192.168.1.1

generate

let { regexp, string } = MatchPattern.generate( [ patternA, patternB, ..., patternZ ] );
  • regexp
    • Regular Expression
    • /^(patternA|patternB|...|patternZ)$/i
  • string
    • string
    • ^(patternA|patternB|...|patternZ)$
  • pattern
    • string
    • *.some.host
    • 192.168.*
    • Don't support ipv6 though