vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Learn Regular Expressions (https://vborg.vbsupport.ru/showthread.php?t=52035)

filburt1 04-23-2003 10:00 PM

Learn Regular Expressions
 
This may look like pure nonsense:
PHP Code:

$s preg_replace("/\[mycode\](.*)\[\/mycode\]/siU""<b>\\1</b>"$s); 

...but it converts anything in $s that's in the format "[mycode]something[/mycode]" to "<b>something</b>". This is thanks to regular expressions, a series of usually arcane-looking characters in a hideous and unreadable string that are extremely powerful once you know how to use them. vB uses them everywhere, and after I got over the very sharp learning curve, I use them everywhere I can now. You'd be amazed at how much it can simplify your code.

A regexp (or regex) reference that I use is at http://www.english.uga.edu/humcomp/perl/regex2a.html (that's for Perl but the expressions themselves are almost exactly the same). Also see http://www.php.net/preg_replace , http://www.php.net/preg_match , and http://www.php.net/preg_match_all , as well as all the other preg_...() functions.

Dean C 04-24-2003 09:18 AM

Good tip filburt. I know how useful they are now ;)

- miSt

Kriek 07-03-2003 12:31 PM

My Regular Expressions are rusty, but I wholeheartedly concur on their potency seeing that I now use them with REGEXP in MySQL queries, while previously only utilizing them within Perl or PHP. I highly recommend this article.


All times are GMT. The time now is 06:22 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01218 seconds
  • Memory Usage 1,711KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete