Hi,
There is an article on perl.com that might be useful: http://www.perl.com/pub/a/2004/01/16/regexps.html
Regexes are a programs. It takes time to learn new languages and that's why it might look difficult at the begining. With time and practice that kind of regex become (almost) clear.
Using /x and commenting is very important but having the right support from the tools you use is also important. Here is a little html document that show your regex colored. I couldn't get it to show directly in this answer so you'll have to copy past :-(:
<HTML>
<HEAD>
<TITLE>Smed generated dump</TITLE>
</head>
<body bgcolor="#FFFFFF">
<FONT color=#000000 style="BACKGROUND-COLOR: #ffffff"> <br> </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #ffffff"> <br> </FONT>
<FONT color=#f00000 style="BACKGROUND-COLOR: #ffffff"> / </FONT>
<FONT color=#ffff00 style="BACKGROUND-COLOR: #ff0000"> .* </FONT>
<FONT color=#ffffff style="BACKGROUND-COLOR: #ff0000"> ( </FONT>
<FONT color=#ffff00 style="BACKGROUND-COLOR: #643296"> [\$#\%>~] <
+/FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #00ff00"> | </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \@ </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #afeeee"> \w </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #f0f0ff"> ~ </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \$ </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #00ff00"> | </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \\ </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \[ </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \\ </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #f0f0ff"> e </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \[ </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #f0f0ff"> 0 </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #f0f0ff"> m </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \\ </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \] </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #f0f0ff"> </FONT>
<FONT color=#ff0000 style="BACKGROUND-COLOR: #ffff00"> \[ </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #f0f0ff"> 0 </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #f0f0ff"> m </FONT>
<FONT color=#ffffff style="BACKGROUND-COLOR: #ff0000"> ) </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #afeeee"> \s </FONT>
<FONT color=#f00000 style="BACKGROUND-COLOR: #f0f0ff"> ? </FONT>
<FONT color=#f00000 style="BACKGROUND-COLOR: #ffffff"> / </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #ffffff"> <br> </FONT>
<FONT color=#000000 style="BACKGROUND-COLOR: #ffffff"> <br> </FONT>
</body>
</HTML>
If your text editor supported this, you would have less problems getting in regexes. There few tools to work on regexes and they do the coloring as well.
Cheers, Nadim (NKH).
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|