http://rubular.com/ is also really great! I use it often when programming ruby regular expressions. Fill in a batch of test strings into the box, then run your regular expression against it, and instantly see (visually) what is happening. This is a BIG plus coming from perl regex 10 years ago ;) This is not a dig a perl regex, but I just remember it was a trial and error loop, where I would continually be iterating the script to see if it worked, where as with this webpage, you just iterate, more quickly.
They also have a great example:
test string:
Today's date is: 9/28/2013.
regex:
(?<month>\d{1,2})\/(?<day>\d{1,2})\/(?<year>\d{4})
result:
month 9
day 28
year 2013
Looking at regex101, the layout of the page looks awfully similar. It seems that the author took Rubular and made it more generic. So yeah, props to Rubular.
What is it with the obsession with regular expressions? They are useful things, sure, but I just use them in connection with grep or if I search for strings and normally they are pretty basic, e.g.
$ grep -r -n --color "foo*bar" src
If I want to validate input data with the machine I just use a parser.
Regexes are an elegant and very powerful way to validate data in scripts in a concise (and if they aren't abused) easy to read fashion. There are almost infinite number of examples, but let's say I want to verify that a field is a 64 Bit hexadecimal MAC address
$mac =~ ^[A-Fa-f0-9]{16}$
Gets the job done. How else, but a regular expression so concisely?
And, when you say, "If I want to validate input data with the machine I just use a parser." - that's pretty much what a regex engine is - a sophisticated parser, and the regular expression is the "commands" that you feed to it to parse the input text.
I have thought about this, but in cases where it would be useful, it's impossible to generate a sample match string. For example, creating a match string for /(?:a|[bc])efg?/ is super simple, but for something like: /(ab(?1)*)/ it becomes much harder. Not to mention the performance hit you would see for these more complex expressions. (These are just dummy expressions for illustrative purposes, but I'm sure you get my gist.)
That's funny. Just yesterday I needed that and used pythex and a bunch of other similar 'testers' to make sure my regular expression was good. It was, but it somehow didn't work on the Mozilla Add-On Builder.
After asking a question on the #jetpack channel, members have spotted the mistake: The regex was correct, but it needed to "match the exact string" as mentioned on the doc. I've read it, but didn't understand that point. There was a missing "." at the beginning and the end. So /.regex.*/
Forgot to tell you how to use it. Simply insert an expression and some text and press the little red button right above the input for the regex. That's all you have to do! Enjoy :)
Not bad. You don't have to jump around your regexp reference and editor. It does not exactly tell you why your exp & string does not match. It just show what typed reg exp will do.
[+] [-] WestCoastJustin|12 years ago|reply
They also have a great example:
Screenshot here: http://i.imgur.com/ixyHRde.png[+] [-] VeejayRampay|12 years ago|reply
[+] [-] egor83|12 years ago|reply
https://www.debuggex.com/
(for Python flavor:
https://www.debuggex.com/?flavor=python )
and one more Python + regex:
http://www.pyregex.com/
[+] [-] helloTree|12 years ago|reply
$ grep -r -n --color "foo*bar" src
If I want to validate input data with the machine I just use a parser.
[+] [-] ghshephard|12 years ago|reply
And, when you say, "If I want to validate input data with the machine I just use a parser." - that's pretty much what a regex engine is - a sophisticated parser, and the regular expression is the "commands" that you feed to it to parse the input text.
[+] [-] unknown|12 years ago|reply
[deleted]
[+] [-] hnriot|12 years ago|reply
when you do understand regex, you'll be amazed at the myriad of things you can do with it.
[+] [-] redox_|12 years ago|reply
[+] [-] joezo|12 years ago|reply
[+] [-] Lindrian|12 years ago|reply
[+] [-] Jugurtha|12 years ago|reply
After asking a question on the #jetpack channel, members have spotted the mistake: The regex was correct, but it needed to "match the exact string" as mentioned on the doc. I've read it, but didn't understand that point. There was a missing "." at the beginning and the end. So /.regex.*/
Thanks for putting this.
[+] [-] Lindrian|12 years ago|reply
[+] [-] unknown|12 years ago|reply
[deleted]
[+] [-] thousande|12 years ago|reply
Here is another regex tester: http://www.gethifi.com/tools/regex
[+] [-] eknkc|12 years ago|reply
[+] [-] hclee|12 years ago|reply
[+] [-] Lindrian|12 years ago|reply
If you don't agree with me, could you perhaps suggest an improvement?
[+] [-] mattyod|12 years ago|reply
[+] [-] shmerl|12 years ago|reply
[+] [-] shocks|12 years ago|reply
[+] [-] SmokyBorbon|12 years ago|reply
[deleted]