vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   Combining 2 preg_replace statements (https://vborg.vbsupport.ru/showthread.php?t=50326)

Boofo 03-17-2003 09:30 AM

Combining 2 preg_replace statements
 
Can someone please tell me how I can combine to 2 following statements into one? I need to parse both of them out of the same code but they seem to cancel each other out.

PHP Code:

$reviewmessage trim(preg_replace("/(\[)(sp)(])(\r\n)*(.*)(\[\/sp\])/siU""<br><normalfont>Spoiler:</normalfont><br><font color=\"$backcolor\">\\5</font>"$post[pagetext])); 

and:

PHP Code:

$reviewmessage trim(preg_replace("/(\[)(you)(])/siU"$bbuserinfo[username], $post[pagetext])); 


Zzed 03-17-2003 10:23 AM

The problem with regex is that you can match patterns with it, but you can't count with them. :(

The following pattern will do the match: ((.*)*(\[you\])*)*

The problem is that due to the repeating nature of the pattern and the fact that it has sub patterns you can not code a replacement for it. :(

You may be stuck with the 2 regex's...

Boofo 03-17-2003 10:26 AM

I don't mind doing 2, but they cancel each other out. One will work, but not the other. Whichever one comes last seems to work. How do I make then both work?

Boofo 03-17-2003 10:29 AM

You said this would do the match. Is this how it should look (with the siU)?

PHP Code:

$reviewmessage trim(preg_replace("((.*)*(\[you\])*)*"$bbuserinfo[username], $post[pagetext])); 


Zzed 03-17-2003 10:33 AM

Not sure if I am being picky here but in the second preg_replace you should change the regex

from "/(\[)(you)(])/siU"
to "/(\[)(you)(\])/siU"

I don't see why they would cancel each other out... :confused:

Zzed 03-17-2003 10:35 AM

Quote:

Today at 04:29 AM Boofo said this in Post #4
You said this would do the match. Is this how it should look (with the siU)?

PHP Code:

$reviewmessage trim(preg_replace("((.*)*(\[you\])*)*"$bbuserinfo[username], $post[pagetext])); 



What I meant was that the regex I gave would replace the (.*) in the first preg_replace and would try to match both patterns in your statements.

But since the replacements need to be done in 2 passes, it is of no help...

Boofo 03-17-2003 10:40 AM

Quote:

Today at 06:33 AM Zzed said this in Post #5
Not sure if I am being picky here but in the second preg_replace you should change the regex

from "/(\[)(you)(])/siU"
to "/(\[)(you)(\])/siU"

I don't see why they would cancel each other out... :confused:

They don't cancel each other out. What is happening is that whichever ones comes last is the one that will work. The other one doesn't parse the code. Only the second (or last) one will.


All times are GMT. The time now is 03:33 AM.

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

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01185 seconds
  • Memory Usage 1,735KB
  • 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
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)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