Jump to content

abareplace

Members
  • Posts

    23
  • Joined

  • Last visited

Everything posted by abareplace

  1. Use two replacements to put </ins> before </br> <?php $a = 'Hello<br <del>/>This is</del> <ins>How are you?<br </ins>/>'; $a = preg_replace( '|<br (<[a-z]+>)/>|', '<br>\\1', $a ); $a = preg_replace( '|<br (</[a-z]+>)/>|', '\\1<br>', $a ); echo $a; ?>
  2. Use preg_match instead of eregi, as the manual suggests. Remember to add delimiters to the pattern.
  3. Hi, Mark, you should check that the word ends here: ([a-z]+)\b(?!( hi)) \b is a word boundary (in this case, the end of the word).
  4. 1) Is ping output separated with commas? 2) If you need to compare the second element of the array with "0", just write if ($data[1] == '0'). No regular expression is needed.
  5. May be, it's a logical vs. visual order problem. Please try to reverse the order: /\p{Arabic)\s*:\s*(\d+)/
  6. AyKay, he wants to find URLs, not email addresses. Monkuar, please try this code: <?php $text = 'abc example.com2 abc'; if (preg_match('/(?<=[a-z0-9])\.(com|org|net|mil|edu|de|us|uk|au|info)/i', $text)) { echo "You cannot post links or urls unless you have made 10 Posts"; } ?>
  7. This is probably what you want: <?php $string = '<b>Age:</b> 16'; if (preg_match('~<b>Age:</b> (\\d+)~', $string, $match)) { echo ((int)$match[1] < 18) ? 'minor' : 'adult'; } ?>
  8. Use preg_match instead of ereg. POSIX regular expressions (the ereg function) are depreciated; you should use PCRE.
  9. If the spaces around commas are optional, then Joe's pattern should be modified in this way: /^[a-z]+\s*,\s*[a-z]+\s*,\s*[a-z]+$/i
  10. Hello, Brian, in most tools, it will not match %%some text%%, because %% is already included in the first match. For example, in PHP: <?php echo preg_replace('/%%(.+?)%%/', '[$1]', '%%match1%% some text %% match2 %% some more text %%match3%%') ?> Output: [match1] some text [ match2 ] some more text [match3] So, you don't have to worry
  11. The Little Guy, you should use a lexer here. There are too many edge cases where regexes will not work. highlight.js is a nice ready-to-use highlighter that does lexical analysis.
  12. Silkfire, the last star (*) is unnecessary: ^(\d+)\D*(\d+) instead of ^(\d+)[^\d]*(\d+)*
  13. Try ... && !phone_number.match(/^(?:1-?)?(\d)\1\1-?\1\1\1-?\1\1\1\1$/)
  14. In TextPad, .* and [^[]* cannot span multiple lines. I've tried \(.\|\n\)* It does not help, too Generally, there are some problems with multi-line searches in TextPad.
  15. McK, I'm sorry. As a geek, I'm paranoidally suspicious Your regex will work if you include the page address into lookbehind: (?<=(user/SendEmail\.jtp\?type=user&user=\d+)">Send Email to ).+(?=<) However, most regex engines don't support variable-length lookbehind (\d+ can have any length, from one character to infinity), so it will work only in .NET, RegexBuddy, or my tool. In PHP, you can use the usual capturing groups: <?php $url = '<a href="/user/SendEmail.jtp?type=user&user=195799">Send Email to shreyes</a>'; $pattern = "/(user\/SendEmail\.jtp\?type=user&user=\d+)\">Send Email to (.+)(?=<)/"; preg_match_all($pattern, $url, $userInfo); echo 'UserAddress: '.$userInfo[1][0] . "<br>\n"; echo 'UserName: '.$userInfo[2][0]; Good luck with your project! It should be very useful for the Protege community.
  16. McK, may I ask, for what are you using the regular expression? Are you trying to collect the email addresses for marketing purposes (i.e. spam)? I'm sorry if the question is rude.
  17. Hi, mck.workman, you can use positive lookahead to check for the presence of ".gh" without including it to the match. <?php $regex = '/http:\/\/www.grasshopper3d.com\/forum\/attachment\/download\?id=2985220%3AUploadedFile%3A[0-9]{6}">[^.]+(?=\.gh)/'; $data = '"http://www.grasshopper3d.com/forum/attachment/download?id=2985220%3AUploadedFile%3A501843">01.jpg</a> "http://www.grasshopper3d.com/forum/attachment/download?id=2985220%3AUploadedFile%3A506981">SURFACE-DIAGRID-TEST.gh</a>'; if (preg_match($regex, $data, $matches)) print_r( $matches ); Read more about lookahead. Hope this helps.
  18. Also note that "/discussion./" matches discussion and any character, not discussion and a dot. You need to escape the dot: "/discussion\./"
  19. As a quick-and-dirty solution, you can replace http in img with some temporary string (hxxp), then replace it back: <?php function txt2link($text){ $text = str_replace( 'www.', 'http://www.', $text ); $text = str_replace( 'http://http://www.', 'http://www.', $text ); $reg_exUrl = "http://(\S+)"; $text = preg_replace('~\[img=' . $reg_exUrl . '\]~i', '<img src="hxxp://$1" alt="">', $text); $text = preg_replace('~' . $reg_exUrl . '~', '<a href="$0" rel="nofollow">$0</a>', $text); $text = str_replace( 'src="hxxp://', 'src="http://', $text ); return ($text); } echo txt2link('[img=http://example.com/image.png] text www.example.com/ http://subdomain.example.com/file.php?p=x text'); ?> Note that you can use ~ as a delimiter to avoid the leaning toothpicks. Top-level domain names can be longer than 3 characters (.info is popular now; future gTLDs will be even longer).
  20. The code removing hyphens and underscores is somewhere else, not in this function. Probably, in filters (apply_filters).
  21. Try this: <?php $regex = '#\\[youtube]http://(?:\\w+\\.)?youtube.com/watch\\?' . '(?:feature=related&)?v=(\\w*)(?:&feature=related)?\\[/youtube]#'; $repl = '<iframe width="560" height="315" src="http://www.youtube.com/embed/\\1" '. 'frameborder="0" allowfullscreen></iframe>'; $subjects = array('[youtube]http://www.youtube.com/watch?v=VDvr08sCPOc[/youtube]', '[youtube]http://de.youtube.com/watch?v=VDvr08sCPOc[/youtube]', '[youtube]http://youtube.com/watch?v=VDvr08sCPOc[/youtube]', '[youtube]http://youtube.com/watch?v=VDvr08sCPOc&feature=related[/youtube]', '[youtube]http://youtube.com/watch?feature=related&v=VDvr08sCPOc[/youtube]'); foreach ($subjects as $subj) echo preg_replace($regex, $repl, $subj) . "<br>\n"; ?>
  22. Sniperscope, try the following code to match the third tag: <?php $id = 'power-push2'; $n = 3; $pattern = '~<div id="' . $id . '">(.*?)</div>~'; $subj = ' blah <div id="power-push2"><a href="../?id=11" class="imghover"><img src="../1.jpg" alt="abc" width="160" height="213" /></a><p><span class="p-w15">username</span></p></div> <div id="power-push2"><a href="../?id=22" class="imghover"><img src="../1.jpg" alt="abc" width="160" height="213" /></a><p><span class="p-w15">username</span></p></div> <div id="power-push2"><a href="../?id=33" class="imghover"><img src="../1.jpg" alt="abc" width="160" height="213" /></a><p><span class="p-w15">username</span></p></div> <div id="power-push2"><a href="../?id=33" class="anotherclass"><img src="whatever, just showing you we can capture several" /></a><p><span class="p-w15">username</span></p></div> <div id="power-push2"><a href="../?id=55" class="imghover"><img src="../1.jpg" alt="abc" width="160" height="213" /></a><p><span class="p-w15">username</span></p></div> blah'; if (preg_match_all($pattern, $subj, $matches, PREG_SET_ORDER) && count($matches) >= $n) { echo ($matches[$n - 1][1]); } ?> Hi, playful. Nice to see you, too
  23. Do you need exactly the third div with this id?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.