Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This will work with the caveat that regex shouldn't be used to parse xml/html, etc..</p> <p>Its always easier to capture simple samples, then sub-process them in a callback.<br> In this case capture ([alphabet"*`,]+), then strip out the unwanted characters, then do a comparison.</p> <p>A Perl sample, the concept is the same for Perl/PHP/C# etc... </p> <pre><code>$sample = ' &lt;hw&gt;Al"pha*bet&lt;/hw&gt; &lt;hw&gt;Al"pha*be`t&lt;/hw&gt; &lt;hw&gt;alphabet&lt;/hw&gt; &lt;hw&gt;al*pha*bet&lt;/hw&gt; &lt;hw&gt;al"pha"b"et&lt;/hw&gt; '; $specialword = 'alphabet'; $uc_specialword = uc( $specialword ); while ($sample =~ m{&lt;([A-Za-z_:][\w:.-]*)(?:\s+(?:".*?"|\'.*?\'|[^&gt;]*?)+)?\s*(?&lt;!/)&gt;([$specialword"*`,]+)&lt;/\1\s*&gt;}isg) { ($matchstr, $checkstr) = ($&amp;, $2); $checkstr =~ s/["*`,]//g; if (uc($checkstr) eq $uc_specialword) { print "Found '$checkstr' in '$matchstr'\n"; } } </code></pre> <p>Expanded regex:</p> <pre><code>m{ # Regex delim &lt; # Open tag ([A-Za-z_:][\w:.-]*) # Capture 1, the tag name (?:\s+(?:".*?"|\'.*?\'|[^&gt;]*?)+)?\s* # optional attr/val pairs (?&lt;!/) &gt; ([alphabet"*`,]+) # Capture 2, class of special characters allowed, 'alphabet' plus "*`, &lt;/\1\s*&gt; # Close tag, backref to tag name (group 1) }xisg # Regex delim. Options: expanded, case insensitive, single line, global </code></pre> <p>Output:</p> <pre><code>Found 'Alphabet' in '&lt;hw&gt;Al"pha*bet&lt;/hw&gt;' Found 'Alphabet' in '&lt;hw&gt;Al"pha*be`t&lt;/hw&gt;' Found 'alphabet' in '&lt;hw&gt;alphabet&lt;/hw&gt;' Found 'alphabet' in '&lt;hw&gt;al*pha*bet&lt;/hw&gt;' Found 'alphabet' in '&lt;hw&gt;al"pha"b"et&lt;/hw&gt;' </code></pre> <p><strong>PHP example's</strong></p> <p>Using <code>preg_match()</code> can be found here <a href="http://www.ideone.com/8EBpx" rel="nofollow">http://www.ideone.com/8EBpx</a></p> <pre><code>&lt;?php $sample = ' &lt;hw&gt;Al"pha*bet&lt;/hw&gt; &lt;hw&gt;Al"pha*be`t&lt;/hw&gt; &lt;hw&gt;alphabet&lt;/hw&gt; &lt;hw&gt;al*pha*bet&lt;/hw&gt; &lt;hw&gt;al"pha"b"et&lt;/hw&gt; '; $specialword = 'alphabet'; $uc_specialword = strtoupper( $specialword ); $regex = '~&lt;([A-Za-z_:][\w:.-]*)(?:\s+(?:".*?"|\'.*?\'|[^&gt;]*?)+)?\s*(?&lt;!/)&gt;([' . $specialword. '"*`,]+)&lt;/\1\s*&gt;~xis'; $pos = 0; while ( preg_match($regex, $sample, $matches, PREG_OFFSET_CAPTURE, $pos) ) { $matchstr = $matches[0][0]; $checkstr = $matches[2][0]; $checkstr = preg_replace( '/[" * `,]/', "", $checkstr); if ( strtoupper( $checkstr ) == $uc_specialword ) print "Found '$checkstr' in '$matchstr'\n"; $pos = $matches[0][1] + strlen( $matchstr ); } ?&gt; </code></pre> <p>Using <code>preg_match_all()</code> can be found here <a href="http://www.ideone.com/C6HeT" rel="nofollow">http://www.ideone.com/C6HeT</a></p> <pre><code>&lt;?php $sample = ' &lt;hw&gt;Al"pha*bet&lt;/hw&gt; &lt;hw&gt;Al"pha*be`t&lt;/hw&gt; &lt;hw&gt;alphabet&lt;/hw&gt; &lt;hw&gt;al*pha*bet&lt;/hw&gt; &lt;hw&gt;al"pha"b"et&lt;/hw&gt; '; $specialword = 'alphabet'; $uc_specialword = strtoupper( $specialword ); $regex = '~&lt;([A-Za-z_:][\w:.-]*)(?:\s+(?:".*?"|\'.*?\'|[^&gt;]*?)+)?\s*(?&lt;!/)&gt;([' . $specialword. '"*`,]+)&lt;/\1\s*&gt;~xis'; preg_match_all($regex, $sample, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $matchstr = $match[0]; $checkstr = $match[2]; $checkstr = preg_replace( '/[" * `,]/', "", $checkstr); if ( strtoupper( $checkstr ) == $uc_specialword ) print "Found '$checkstr' in '$matchstr'\n"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload