in reply to using just variables in a regular exression

You have good answers to your question above. Now, please consider the manner of your asking.

IMO, you're apt to confuse readers -- especially the newcomers whose education is a major goal of the Monastery -- by posting pseudocode without clear indication that that's what it is. And for something this simple, the Monastery's standard is (slightly paraphrased) post a snippet of compilable, executable code (cf: How do I post a question effectively?).

Omitting semi-colons and regex delimiters merely obfuscates; including them (and the other niceties of compilable code) would cost you very little but would provide the community much greater ease of reading.
  • Comment on Re: using just variables in a regular exression

Replies are listed 'Best First'.
Re^2: using just variables in a regular exression
by sdetweil (Sexton) on Aug 31, 2012 at 03:18 UTC
    Ok, I'll play along.. I don't like obtuse code, so I use a lot of whitespace.
    and my last issue was with the modifiers, which ended up needing eval().
    if (startsWithIgnoreCase(trim($expstr),"s") || startsWithIgnoreCase(tr +im($expstr),"m")) { # split the string my @t = split( /\//, $expstr); if(startsWithIgnoreCase(trim($expstr),"s")) { if(@t>3) { $t[3]=~s/e//g; SyntaxDebug("new regex modifier parameter=".$t[3]."\n"); if($debugFlag==$true) # 1.52 { use re 'debug'; eval("$expdata=~ s/$t[1]/$t[2]/".$t[3] .";"); $k = $expdata; } else { eval("$expdata=~ s/$t[1]/$t[2]/".$t[3] .";"); $k = $expdata; } } else { if($debugFlag==$true) # 1.52 { use re 'debug'; $expdata=~ s/$t[1]/$t[2]/; $k = $expdata; } else { $expdata=~ s/$t[1]/$t[2]/; $k = $expdata; } } SyntaxDebug("substitution=" . @t . " result=". $k . "\n"); } else { if($debugFlag==$true) # 1.52 { use re 'debug'; $expdata=~ m/$t[1]/; $k = $$expResult; } else { $expdata=~ m/$t[1]/; $k = $$expResult; } SyntaxDebug("match=" . @t . " result=". $k . "\n"); } } else { if($debugFlag==$true) # 1.52 { use re 'debug'; $expdata=~$expstr; $k=$$expResult; } else { $expdata=~$expstr; $k=$$expResult; } if (!defined($k)) { $k=$emptyString; } SyntaxDebug("parse expr='".$1."' k='".$k ."'\n"); }
    thank you Sam