Thursday, June 4, 2015

Jarextor: JavaScript Regular Expression Testor

This actually can be done right on the browser, on the developer console.
But, we have to type the input first. Like, the complete input variable, syntax and such.

This tool is equipped with default text you can capture with RegEx.
This can also use your own text by clicking the text element and then type your own string there.

This is a client side (browser) application.

JAREXTOR

notifier #1
notifier #2
Jarextor

Example

  • On the left (pattern) input, type /a/ (finding "a" character)
  • On (small) right (flag) input, type g (global)
You'll see the result.

Other examples
  1. Matching URL protocol, either http:// or https://
    /https?:\/\//g
    • The s? means the character s is optional, 0 or 1 repetition.
    • We need to escape the slash (/) with backslash. Thus the // becomes \/\/
  2. Finding all "t" character and case insensitive (additional i flag):
    /t/gi
  3. Finding all double "t"s:
    /t{2}/g
  4. Finding all words starting with "t" and have "g" as the tail. And also case insensitive:
    /t[a-z]+g/gi
    • [] is the bracket to match any character within it.
    • a-z means match any alphabet (lowercase a through z).
    • The + meta-character is to match the preceding character (which is "[a-z]") one or more times. So it can be one character or a group of characters.
  5. Finding all words (with only alphabet) which don't have "t" in it and using case insensitive flag:
    /\b[^t\s\W\d_]+\b/gi
    • \b at the front and back are to match word boundaries.
    • ^ within the bracket is to match other characters than the ones defined inside it: t, \s, \W, \d, and character _ (underscrore).
    • The \s meta-character is whitespace (horizontal/vertical, tab, etc).
    • The \W meta-character is to match non-word.
    • The \d meta-character is to match digit (number).
    It can be also simplified as /\b[a-su-z]+\b/gi or maybe others.

Start by browsing Wikipedia or Stack Overflow or epic blogs about RegEx basic and snippets (especially for JavaScript purpose). It can have a very, very complicated pattern. It depends on what is the thingy we need to capture.


Anywho, if you put HTML tags as text reference input...
This tool will try to "ignore" those. Sometimes it can, but most of the time you'll see weird things. Please use other than wrapped in <...>.