About

JRX is inspired by the RX tool of ActiveState's Komodo IDE. Although RX is more powerful and supports Perl Regular Expressions (almost?) fully, I've needed an always-accessible and installation-free implementation.

So, here it is: a single, ultra-compact HTML file, without any external file ;)

Save it to your disk if you like, or use online for latest version.

You might also be interested in Ted Mielczarek's Extension Developer's Extension, it includes JRX among some other very useful stuff, it's terrific!

This is not an AJAX application, you can save the page locally and use it off-line.

Compatibility

I'd tested older versions of JRX with Mozilla 1.3, IE 6.0 and Opera 7.1, and JRX worked OK in all of them.

However, IE6 and Opera have had back then some funny bugs with JavaScript and CSS, and I'm getting tired of IEs inferior CSS/JS-support (I'm not sure of IE7, I don't have it). Therefore, I was testing the latest versions only with Mozilla Firefox >=v1.5; JRX may or may not work in Opera.

I'd be happy if you can come up with code submissions which fix things with IE/Opera, but most likely I will not do it myself.

I'm still keeping the latest working version for IE/Opera anyway.

Have fun.

Recent changes

I've added matched substrings' starting and ending positions to the results list

Clicking or hovering on the results will highlight matched portion on the target text and double-clicking will jump to the textarea; unfortunately you cannot scroll the textareas to the selected portion :(

Hovering over the results will show the parenthesized substrings

Target text can be evaluated before the matching is done (see below for explanation)

RegExp-based replacements; also if you have parenthesized groups, you can use $1, $2, etc. or $&

I've changed the split code, it now does not use String.split(), since String.split() doesn't know about matched portions' positions

Settings are automatically saved via cookies (yippee!) and your last regexp and text will be preserved; note that cookies will not work if you work locally

work if you work locally There's a compact mode now, JRX should easily fit into smallest browser windows (see the note about this option & re-distribution below)

Number of iterations is hard-limited to 250, in order to avoid infinite evaluations (e.g. due to backtracking)

Got rid of "Auto-update" option, "Refresh" & "Clear text" buttons

Changed the accesskeys so that most of them can be accessed with the options' first letters

Fixed a bug with regexps using *, e.g. /b*/ matched against "Hello world" repeatedly the first empty string (pos:0->0)

Lots of small changes and some cleanup in code

Unfortunately, I have no time to implement lots lots of workarounds for IE's bugs, so I will rarely test JRX with IE from now on and write code for IE only if it's extremely easy!

Unless new bugs are discovered, I'll add no more features to this beta and release it as final.

To do

I'm considering to add a few other tools and cosmetic changes, such as:

Regexp examples for common tasks, e.g. matching dates, emails, domain names, etc.

Perl-style extended regular expressions, i.e. with multiple lines, comments, etc, but it's no top priority at the moment; contact me if you can help on this

A tabbed interface (why?!?)

Real-time JavaScript Evaluator(why?!?, there is this awesome JavaScript Shell and another terrific JavaScript Development Environment)

Hexadecimal<->Decimal converter

Encoder-Decoder using un/escape(), de/encodeURI(), de/encodeURIComponent() (I'm letting myself go)

The subroutine which will compute the answer to life, the universe and everything

Though these might be useful to do everything on one place, it will also bloat the page, so they might be never implemented.

Mini FAQ

Q. Why are my results shown twice, if I use global and parentheses?

A. Results always include $0, which means, if you use, e.g. (^.*$), $0 is implicitly the whole matched string and $1 is your backreference!

Now if you pack your whole regexp into parentheses, $0 & $1 will be naturally the same, therefore shown twice:)

...try the above regexp with multiline(m) & global(g), and you'll see.

Results show only $0 now, hover over the results to see the substrings.

Q. What does "Eval target text" do?

A. It substitutes escaped chars \t \r

\f \v with their respective values, before matching the regexp!

To see this in action enter "foo \t bar" as target text and "(\S+)(\s+)(\S+)" as regexp

and try matching with and without this options.

Note that the inline linebreaks in the target are not escaped; you should use

in that case.

Also note that the highlighting does not function well when this option is active, yet.

Q. Why is text length shown "incorrectly" if use newlines?

A. (Firefox') HTML textareas interpret Enter key as ASCII code 0x0A (aka

) and "a<ENTERKEY>b" returns a length of 3 whereas other editors show a length of 4 using 0x0D+0x0A (aka \r

).

So be cautious if text length is extremely important for you and/or if you match/split by

, \s, etc.

Q. How can I backreference inside my regexp?

A. For example, to match ISO-type dates (yyyy-mm-dd) you could use (\d{4})([/.-])(\d{2})\2(\d{2}) (this is a practical example, but not validating). Note the \2 it ensures that the same delimiter is used afterwards.

BTW, a complete date-validating regexp is nearly impossible, due to the leap years, but an approximate solution would be: (\d{4})([/.-])(0\d|1[0-2])\2([012]\d|3[01]), though this would match 9876-02-30, too, I'll leave the rest as an exercise.

Keyboard shortcuts

You can recognize shortcuts on underlined letters. Firefox used to have ALT as modifier key and later versions use ALT-SHIFT.

Modifier-E Expression box Modifier-T Target text box Modifier-A About Modifier-G Global matching Modifier-M Multi-line mode Modifier-S Single-line mode Modifier-I Ignore case Modifier-I eXtended regexps Modifier-P sPlit mode Modifier-R Replace mode Modifier-C Compact mode Modifier-H sHow mini reference

Quick Regular Expressions reference

\d any decimal digit \D any char that is not a decimal digit \s any whitespace char \S any char that is not a whitespace \w any word char \W any non-word char \b word boundary; inside char-class: backspace \B not a word boundary \A start of subject (independent of multiline mode) \Z end of subject or newline at end (independent of multiline mode) \z end of subject(independent of multiline mode) [] char class ^ beginning of line; inside char-class: negate $ end of line () capturing parentheses | alternation * zero or more time, equals to {0,} + one or more time, equals to {1,} ? zero or one time, equals to {0,1} {m,n} preceding char or group minimal m, maximal n times (?:) non-capturing parentheses (?=x) lookahead, i.e. only if followed by x (?!x) negated lookahead, i.e. only if not followed by x (?<x) lookbehind , not supported by JavaScript (?<!x) negated lookbehind , not supported by JavaScript \f form-feed \t tab \v vertical-tab \r carriage return

new line (unix:

, win:\r

, mac:\r) \xhh hexadecimal code of char (2 hex) \uhhhh unicode code of char (4 hex)

Copy issues

Distributed under GNU License.

Modifications are allowed as long as credits are preserved and visible ,

i.e. you may not re-distribute this page in its compact form, i.e. with page header and footer being hidden!

Email portion of this program courtesy of: Jim Tucek

Other portions of code which are used in this page are fully documented and credited in the source code.

Credits and thanks