Regexp helper - any suggestions?

Posted by Nick Gammon on Thu 30 Dec 2004 11:14 PM — 5 posts, 13,409 views.

Australia Forum Administrator #0

As a final tweak to version 4 of MUSHclient, I am adding a helpful 'regexp helper' menu. What this does (intends to do anyway) is to make it easier to generate regular expressions by letting you choose common actions from a menu, see example below ...

My question for people who use regular expressions regularly is: 'Are there other things you would like to see on the menu?'

I want the menu to be useful but not too cluttered with things you don't normally need (there is the documentation for that).

Australia Forum Administrator #1

Below are the characters that get inserted for each menu item:

Any Character .
Character In Range []
Character Not In Range [^]
Whitespace \s
Not Whitespace \S
Decimal Digit (0-9) \d
Not Decimal Digit \D
Letter (A-Z) [[:alpha:]]
Not Letter [[^:alpha:]]
Word (A-Z, 0-9, _) \w
Not Word \W
Beginning Of Line ^
End Of Line $
End Of Subject \z
Word Boundary \b
Tagged Expression ()
Named Expression (?P<name>)
Or |
Comment (?#)
0 or More Matches {0,}
1 or More Matches {1,}
0 or 1 Match {0,1}

If the table disagrees with the screenshot, it is because I have started tweaking the descriptions a bit. The table above is what is planned in the release.

Amended on Thu 30 Dec 2004 11:46 PM by Nick Gammon
Australia Forum Administrator #2
Some other possible candidates are:

[[:alnum:]] letters and digits
[[:ascii:]] character codes 0 - 127
[[:blank:]] space or tab only
[[:cntrl:]] control characters
[[:digit:]] decimal digits (same as \d)
[[:graph:]] printing characters, excluding space
[[:lower:]] lower case letters
[[:print:]] printing characters, including space
[[:punct:]] printing characters, excluding letters and digits
[[:space:]] white space (not quite the same as \s)
[[:upper:]] upper case letters
[[:word:]] "word" characters (same as \w)
[[:xdigit:]] hexadecimal digits

\ general escape character

USA #3
Sounds like a great idea, Nick. How difficult would it be to have submenus? I imagine it might make things a little easier (and less cluttered, thus allowing more stuff *grin*) if you have submenus for things like:
- character class
- quantifiers
- position markers
- grouping

As far as more things on the menu, your list seems fine to me. With submenus, you could have more, even the less frequently used stuff... you could put that stuff into a separate category.
Australia Forum Administrator #4
Good idea. I've made a few submenus instead of one big one, but most of it is the same as listed above. I've also added:

[[:alnum:]] letters and digits
[[:lower:]] lower case letters
[[:upper:]] upper case letters
[[:xdigit:]] hexadecimal digits

and:

Group Without Capture: (?:)

Positive Lookahead: (?=)
Negative Lookahead: (?!)
Positive Lookbehind: (?<=)
Negative Lookbehind: (?<!)

4 Matches Exactly: {4}
5 to 10 Matches: {5,10}

The last two are really examples, to show how you might match 4 things (eg. a{4} would match "aaaa") or a range (eg. 3 to 5 digits would be: [0-9]{3,5} )