Tags:
create new tag
, view all tags
if( ( $str =~ /(^|[^\S])$name\s*=\s*\"([^\"]*)\"/ ) && ( $2 ) ) {

<and>

if( ( $str =~ /(^|\=\s*\"[^\"]*\")\s*\"([^\"]*)\"/ ) && ( $2 ) ) {

elsif( ( $str =~ /^\s*\w+\s*=\s*\"([^\"]*)/ ) && ( $1 ) ) {

These regular expressions come from sub extractNameValuePair in the TWiki.pm file of the 20010901 release of TWiki.

I copied these from my TWiki20010901.leo file (from home, possibly slightly different (more up-to-date) than the one currently attached to TWikiInLeo). Posted here to see if it helps LynnwoodBrown -- see HelpWithSearches.

Since my eyes are starting to cross, I'm going to save this exactly as is for now -- it is quite likely that if it is viewed in TWiki it will not appear correct due to TWiki's rendering. You may need to edit it, or view it "raw" to see it correctly. Eventually I will try to make it appear correct in view -- it may be as simple as enclosing the entire thing in <verbatim> tags.

Ok, I made a first pass through this to make it read more correctly -- I "escaped" the <s. Not sure that is enough, but it should help as a lot of stuff was not visible.

BTW, this might or might not be the regular expression I was thinking of, with 10 long lines of comments. It was the first long one I came to. Skimming through it today, the comments do not immediately help the meaning jump out at me. I thought I had done a better job. Maybe there is another regular expression in the file with 10 long lines of better comments. Won't look now, but I know where to start the (manual) search from (in the Leo file), next time I try.

See:

Analyze these:

if( ( $str =~ /(^|[^\S])$name\s*=\s*\"([^\"]*)\"/ ) && ( $2 ) ) {

if( ( $str =~ /(^|\=\s*\"[^\"]*\")\s*\"([^\"]*)\"/ ) && ( $2 ) ) {

elsif( ( $str =~ /^\s*\w+\s*=\s*\"([^\"]*)/ ) && ( $1 ) ) {

Now, using the tidbits from below:

if( ( $str =~ /(^|[^\S])$name\s*=\s*\"([^\"]*)\"/ ) && ( $2 ) ) {

Looks at $str to find $name at the beginning, or preceded by whitespace only, followed by zero or more whitespaces, "=", zero or more whitespaces, a ", zero or more non ", and finally a " (not necessarily the final thing on the line). The almost last portion, the stuff enclosed in quotes, is assigned to $2. Then, if the match is successful and $2 exists (is non null), the then clause ({}) of the if statement is executed.

Now, condense that one more time:

It looks to find ^\s$name\s=\s"<something>". <something> is assigned to $2. If <something> exists (is non null), the then clause is executed.

if( ( $str =~ /(^|\=\s*\"[^\"]*\")\s*\"([^\"]*)\"/ ) && ( $2 ) ) {

Looks at $str to find an optional initial =, followed by zero or more whitespaces, a ", zero or more non ", and a ", zero or more whitespaces, a ", zero or more non ", and finally a " (not necessarily the final thing on the line). The almost last portion, the stuff enclosed in quotes, is assigned to $2. Then, if the match is successful and $2 exists (is non null), the then clause ({}) of the if statement is executed.

Now, condense that one more time:

It looks to find =\s"<something1>"\s<something2>" or \s"<something1>"\s<something2>". <something2> is assigned to $2. If <something2> exists (is non null), the then clause is executed.

elsif( ( $str =~ /^\s*\w+\s*=\s*\"([^\"]*)/ ) && ( $1 ) ) {

Looks at $str to find zero or more initial whitespaces followed by one or more word characters (alphabetic, numeric, or an underbar, zero or more whitespaces, an =, zero or more whitespaces, a ", and finally zero or more non " (not necessarily the final thing on the line). The almost last portion, the stuff following the second open quote, is assigned to $1. Then, if the match is successful and $1 exists (is non null), the then clause ({}) of the elseif statement is executed.

Question: shouldn't the pattern look for a final " ??

Now, condense that one more time:

It looks to find =\sword\s=\s"<something>. <something> is assigned to $1. If <something> exists (is non null), the then clause is executed.

Tidbits:

[^\"] matches any single character except a "

[^\S] matches whitespace -- [ \r\t\n\f] (note space after [)

/[\S]/ is the same as /[^ \r\t\n\f]/ (note space after ^) /[\s]/ is the same as /[ \r\t\n\f]/ (note space after [)

Shouldn't /[^\S]/ be the same as /[\s]/? Yes, I think it is, and it seems to test out that way -- I don't know why it's phrased this way -- I may need to test it at some point.

Ahha! (^|[^\S])$name has the effect that $name must either be the first thing on the line, or be preceded by whitespace only!!

^|\= amounts to an optional "=" at the beginning of a line

<Currently, no significant content below this line.>

Contents


Contributors

  • () RandyKramer - 19 May 2002
  • <If you edit this page: add your name here; move this to the next line; and include your comment marker (initials), if you have created one, in parenthesis before your WikiName.>

Page Ratings

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2002-07-26 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look