Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Details »»

Version: , by JJR512 JJR512 is offline
Developer Last Online: Jun 2006 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 02-18-2002 Last Update: Never Installs: 0
 
No support by the author.

When you're using the ereg() expression, and you have multiple items inside it, such as this:
PHP Code:
ereg('^(M?)([0-9]{1,2})(/?)([0-9]{1})?SM$',$group,$regs
Does it matter if the ? symbols go inside or outside the ()s? It looks to me like sometimes it does matter, sometimes it doesn't. That sample line was giving me a lot of trouble in the form of this error message: "Warning: REG_BADRPT in /home/jjr512/public_html/forums/xxxx.php on line 40". Originally, I had the last ? (the one right before the SM) just inside the ) that's now right before it. When I moved it to just outside that ), which is how you see it now, the problem went away. But there are still two instances of a ? inside some ()s earlier on that line, and that doesn't seem to be a problem; why is that?

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 02-18-2002, 08:01 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's because you had something like this:
Code:
[0-9]{1}?
{1} means you only want one digit, right? But "?" means you want it to appear 0 or 1 times. That's not right, because you have two quantifiers on the same expression ([0-9]).
By putting ? outside the parentheses, you are saying you want the whole thing (a digit that appears exactly once) to appear 0 or 1 times, which is better (but still pointless ).

There is no need in putting {1} because that has no affect on the outcome of the regex.

Also you should use preg_match(), it's faster.
Reply With Quote
  #3  
Old 02-18-2002, 05:52 PM
JJR512's Avatar
JJR512 JJR512 is offline
 
Join Date: Oct 2001
Location: Glen Burnie, MD, USA
Posts: 710
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So I could either use ([0-9])? or ([0-9]{0,1}) and either is the exact same thing, correct?

Also, as to the preg_match, do I just replace all instances of "ereg" with it, or do I need to recode anything (in other words, is it the exact same syntax)?
Reply With Quote
  #4  
Old 02-19-2002, 11:05 AM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, not exactly the same. You need to add delimiters before and after the expression. Most use / as the delimiter but I prefer # as it's less likely to appear in the expression itself (because if / is in it, you must escape it like \/).

The parentheses matter, don't get me wrong. The matches you will have in the $regs array will only contain what's between them. So if you put something out of the parentheses, you won't get it in the matching array.
Reply With Quote
  #5  
Old 02-19-2002, 05:20 PM
JJR512's Avatar
JJR512 JJR512 is offline
 
Join Date: Oct 2001
Location: Glen Burnie, MD, USA
Posts: 710
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So what would be the best way to write an expression that looks for either a single digit or no digit?

Looking at my original expression,
PHP Code:
ereg('^(M?)([0-9]{1,2})(/?)([0-9]{1})?SM$',$group,$regs
What I really want is to find any of the following:
M1/1SM
M1SM
M11SM
1/1SM
1SM
11SM
(where '1' represents any single-digit number, all other characters are literal)

Any of those substrings will be surrounded by a blank space on both sides.

SM will always appear in it, and will always be preceded by at least one digit, possibly two. If it's preceded by one digit, that one digit may or may not be preceded by an M. If that one digit is not preceded by an M, it may or may not be preceded by a forward slash; if it is, it must be preceded by another single-digit number, and that single digit may or may not be preceded by an M. If the SM is preceded by two digits, those two digits may be preceded by an M, and that's it. And how I need all that grouped into something I can work with (by putting it into $regs[x]) is that each element should be separate, unless it's two digits together, because that is one number. Also, if there is a forward slash, the single digit before it and the single digit after it, and the slash, can all go together, although I think it would be easier to smash them together later (that is a fraction).
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:49 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.03767 seconds
  • Memory Usage 2,240KB
  • Queries Executed 18 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (4)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete