vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   need help for .... ereg_replace ... to replace number (https://vborg.vbsupport.ru/showthread.php?t=146169)

humax9110 05-01-2007 10:31 AM

need help for .... ereg_replace ... to replace number
 
hello every body,

I want to replce the number (between 7 to 11 digit) to (U can't post number) by using ereg_replace

I made this

$message = ereg_replace('[0-9]{7,11}','(u can't post number)',$message);

but this will replace all number even that 1234678.gif or 12345678.jpg

what I want that to replace only sprate number Neither *12345678 nor 12345678* mean if there is char. before or after number not replace the number ....

Thanks ...

ElfMage 05-02-2007 04:21 AM

Take a look at the lookaround syntax described here: http://www.regular-expressions.info/refadv.html

You could use something like this:

'[\d]{7,11}(?![\d]+)'

This uses a zero-length look ahead.

The problem with the look-behind is that some regex engines only allow plain text in the look-behind.

But, if you know what could be before the number you are matching, you could craft that into the regex.

I am sure there is a simpler way.... :rolleyes:

humax9110 05-02-2007 09:31 AM

Quote:

Originally Posted by ElfMage (Post 1239468)
Take a look at the lookaround syntax described here: http://www.regular-expressions.info/refadv.html

You could use something like this:

'[\d]{7,11}(?![\d]+)'

This uses a zero-length look ahead.

The problem with the look-behind is that some regex engines only allow plain text in the look-behind.

But, if you know what could be before the number you are matching, you could craft that into the regex.

I am sure there is a simpler way.... :rolleyes:

Thanks ...

before number not characters or = or :

after number not characters or .

I Waited for ur help :up:

ElfMage 05-03-2007 03:16 AM

:)

You can do this:
PHP Code:

$message preg_replace
       
'#([^a-z\=\:]*)[\d]{7,11}([^\w\.]*)#si'
        
'\1u can\'t post numbers\2'
        
$message
    
); 

I used preg_replace because I am more familiar with that, but you can easily adapt the patterns to ereg_replace.

Basically what the code above is (supposed to be) doing is:

* Find any series of characters that are not characters, = or : (0 or more), and capture that into \1
* Followed by 7 to 11 digits (not captured)
* Followed by any non-character or ., and capture it into \2

And then replace that with the captured groups \1, your message, and \2.

I think that you mentioned in your last post differs from your original post, but you get the idea, you can change this to suit your needs.

humax9110 05-03-2007 10:06 AM

Quote:

Originally Posted by ElfMage (Post 1240324)
:)

You can do this:


I used preg_replace because I am more familiar with that, but you can easily adapt the patterns to ereg_replace.

Basically what the code above is (supposed to be) doing is:

* Find any series of characters that are not characters, = or : (0 or more), and capture that into \1
* Followed by 7 to 11 digits (not captured)
* Followed by any non-character or ., and capture it into \2

And then replace that with the captured groups \1, your message, and \2.

I think that you mentioned in your last post differs from your original post, but you get the idea, you can change this to suit your needs.

Thanks for ur trying to help me ... but
what I need it is diffrent

PHP Code:

$post['message'] = preg_replace
       
'#([^a-z\=\:]*)[\d]{7,11}([^\w\.]*)#si'
        
'\1u can\'t post numbers\2'
        
$post['message']
    ); 

This will replace 12345678.gif to can't post numbers and this what I don't want it ...


I don't want replace these

1234567.gif
123455678.jpg
1245663.swf
=12345678

magnus 05-03-2007 11:34 AM

<a href="http://www.regular-expressions.info/anchors.html" target="_blank">Use anchors.</a>

Eikinskjaldi 05-04-2007 05:29 AM

hows about...
PHP Code:

$post['message'] = preg_replace
       
'/([^|[^a-z0-9=:])[0-9]{7,11}($|[^\.a-z0-9])/si'
        
'\1u can\'t post numbers\2'
        
$post['message']
    ); 



All times are GMT. The time now is 07:23 PM.

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.01164 seconds
  • Memory Usage 1,733KB
  • 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
  • (3)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