Powered by eUKhost®

Announcement

Collapse
No announcement yet.

PHP Howto: Do I need to use forward slashes at the start and end of a regular expression?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP Howto: Do I need to use forward slashes at the start and end of a regular expression?

    All regular expressions in PHP (i.e. regular expressions using preg_match(), preg_replace() and other PCRE functions) must have delimiters - that is, to specify the start and end of a regular expression. However, you don't need to strictly use the forward slash character. In fact, you can use the hash/pound character ( # ) or perhaps the plus character ( + ) and many others.

    Example:
    Code:
    $regex = preg_match( '|[a-zA-Z]+|',$string);
    Remember, if you need to use the character that is your delimiter within your regular expression, it needs to be preceded with a backslash so PHP ignores it and treats it as a literal character and not as the end of your regular expression.
    Find us on Twitter and Facebook

    Need to contact us?
    Customer Support: Client Area - 0800 862 0380 (option 2)
    Customer Relations: [email protected] - 0800 862 0380 (option 3)
    Sales: [email protected] - 0800 862 0380 (option 1)




    The opinions or views expressed above are not necessarily the opinions or views of eUKhost Ltd.
ban-img
Working...
X