Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular Expression Help

Status
Not open for further replies.

Trope

Programmer
May 14, 2001
110
US
I wanted to learn about regular expressions, so I decided to build a "regular expression" tool that would allow you to 'build' your expressions, test them, etc. 'The best way to learn is by teaching...or something like that, right?' :)

The app is at:


I am now at the phase of handling sytnax errors, but the more code I write, the more I am seeing that the number of syntax error possibilities are staggering. For instance, if you visit the app and enter a ? as the first character of your expression, you will notice that I have trapped that particular error.

Does anyone know of any "rules of thumb" regarding reg exp syntax? Below is part of the syntax error checking - in this example I am checking for syntax errors related to the ? metacharacter:

// -------------------------------------------------------
// Syntax Error Check - ?
// -------------------------------------------------------
reSyntax = /([^\\].[$\+\*\^bB\|]\?)/gi;
arrSyntaxResult = re.match(reSyntax);
if(arrSyntaxResult){
retStr = &quot;<b>The error <i>appears</i> to be located in the following group of characters, and related to the ?: &quot; + arrSyntaxResult.toString() + &quot;</b><p>&quot;;

retStr+=questionStr; // Just a help string
return retStr;
}

As you can see, I am only checking for invalid characters to the LEFT of the metacharacter ( while making sure that it is not escaped ).

IS THERE AN EASIER WAY TO DO THIS??????????????????????
Does Javascript's Reg Expressions have some sort of Error property that I can access??? ( fingers crossed! )
Thanks for any help offered!

Trope
 
very cool - nice work, except doesn't work in Moz so you don't get two thumbs up.

error property? not that i know of.

i don't even want to begin thinking of how many syntax errors are possible...though if you finish, people would probably pay for your tool.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Thanks Jeff - I appreciate your comments.

I will continue my work. It is time consuming. I wrote a brute force script that tries each and every combination for each metacharacter. If an error is returned, that character (group of characters) is added to the array. Since RE's only apply to characters to the left, excluding the new [pattern=] future check, I am only checking three chars deep to the left to allow for escaped chars.

The script has been running for 9 days now - and is 23% done. And believe it or not, the number of error combinations is not near as high as I thought, and most are repetitive.

Onward I march. I'll present the final version in, say...36 more days???

Nice site you have btw, clean & cross browser friendly. :)

Ciao!!
Giovanni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top