Page 1 of 1
shortened character sets
Posted: Wed Jul 02, 2008 8:15 pm
by anandm
I am learning REGEX and this tutorial I am using says that in place of commonly used character sets I can use short forms
eg:- \d is short for [0-9]
OR
\w stands for "word character", usually [A-Za-z0-9_]
This doesn't seem to work for me in Textpad. I have tried with the Posix option both on and off.
Any ideas?
Thanks
Posted: Wed Jul 02, 2008 8:48 pm
by Bob Hansen
The RegEx syntax used n TextPad is different from the one used in your tutorial.
Check out the TextPad Halp for "Regular Expressions" and "How To Use Regular Expressions".
Posted: Wed Jul 02, 2008 8:51 pm
by talleyrand
The regular expression engine in TextPad doesn't have as much power as you will find in modern libraries. I tend to use a site like
http://regexlib.com/RETester.aspx as a harness for testing my expressions
From the help under Character Class Operators
"These can be used as an alternative way of representing classes of characters. For example, [a-z] is equivalent to [[:lower:]] and [a-z0-9] is equivalent to [[:lower:][:digit:]]. (Note the extra pairs of brackets.)"
Thus, after checking Regular Expression on your search, \w would be translated as [[:word:]]
If you are using TP's regex, you will most likely want to make it use Posix syntax so Configure, Preferences, on the Editor tab, check "Use POSIX regular expression syntax"
Posted: Wed Jul 02, 2008 9:06 pm
by anandm
Thanks guys. My intent is to use my new knowledge in php eventually. Was using Textpad as a learning tool. The tutorial recommended to download editpad but I already had Textpad, so I thought I'd go with that.
I Just opened up a large text file and try various search strings to see how it behaved.
I do have the POSIX option on, something I discovered after I started to play with it.
And as you say [:blah:] does work like the \d and \w but is still a darned sight longer to type!