tags:

views:

325

answers:

5
^(?!-)[a-z\d\-]{1,100}$
+14  A: 
pho3nix
http://www.regexbuddy.com/
Simucal
where did this nifty output come from?
ennuikiller
I have regexbuddy is a software where i can construct and edit regex strings only i need introduce my regex and give what is this. Very cool software and cut me very time in work.
pho3nix
You beat me too it, I was going to post the same picture! I second regexbuddy, its a GREAT way to learn about Regex, it really has helped me!
micmoo
I don't see how it helps learn about Regex,though:(
Shore
@Shore, how can you not see a character-by-character explanation of regular expressions as being a useful tool in learning them?
Simucal
Does it highlight which part of the regex it coresponds to?
Shore
Yeah, you type in an example string, and it highlights which part matches the regex. Its learning through try-it-yourself... give it a download, its free (and runes fine in wine if your on OS X or linux)
micmoo
wow,it's cool then.it's essentially a tiny regex compiler.
Shore
+4  A: 

(?!-) == negative lookahead

start of line not followed by a - that contains at least 1 to 100 characters that can be a-z or 0-9 or a - followed by the end of the line, though the \d in the character class is probably wrong and should be specified by 0-9 otherwise the a-z takes care of a 'd' character, depends on the regex flavor.

Qberticus
+5  A: 

Here's an explanation using regex comment mode, so this expanded form can itself be used as a regex:

(?x)      # flag to enable comment mode
^         # start of line/string.
(?!-)     # negative lookahead for literal hyphen (-) character, so fails if the next position contains one.
[a-z\d\-] # character class matches a single alpha (a-z), digit (\d) or hyphen (\-).
{1,100}   # match the above [class] upto 100 times, at least once.
$         # end of line/string.

In short, it's matching upto 100 lowercase alphanumerics or hyphen, but the first character must not be hyphen.

Could be attempting to validate a serial number, or similar, but it's too general to say for sure.


Not all regex engines support negative lookaheads. If you're trying to figure out what it is doing in order to adapt for an engine without negative lookaheads, you can use:

^[a-z\d][a-z\d-]{0,99}$
Peter Boughton
+1  A: 

RegExBuddy is good, but it is a 3 month 'tryware'.

There is one more such freeware, The RegEx Coach,

The Regex Coach is a graphical application for Windows which can be used to experiment with (Perl-compatible) regular expressions interactively. It has the following features:

  • It shows whether a regular expression matches a particular target string.
  • It can also show which parts of the target string correspond to captured register groups or to arbitrary parts of the regular expression.
  • It can "walk" through the target string one match at a time.
  • It can simulate Perl's split and s/// (substitution) operators.
  • It tries to describe the regular expression in plain English.
  • It can show a graphical representation of the regular expression's parse tree.
  • It can single-step through the matching process as performed by the regex engine.
  • Everything happens in "real time", i.e. as soon as you make a change somewhere in the application all other parts are instantly updated.

And, you can donate through PayPal if you want to put in some money.

nik
A: 

A string of letters, digits and dashes. Between 1 and 100 characters. The first character is not a dash.

Jeremy Stein