Jump to content

bobbinsbro

Members
  • Posts

    385
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male

bobbinsbro's Achievements

Member

Member (2/5)

0

Reputation

  1. thank you very much, that did the trick. i didn't know about greedy and non-greedy. nice to learn new things.
  2. the pattern i gave is part of a much longer pattern, that is supposed to match long blocks of text containing many quote-delimited strings. i originally tried what you suggested, but preg_match() didn't stop at the first quote (the one on which i need to end the sub-pattern) but rather continued to the very last quote, counting all intermediate quotes as part of the (.*) sub-pattern. so i tried using matching any character that isn't the backreference to force preg_match() to stop on the first quote found. i need to use the back reference because i need to allow both single and double quotes in all places, and i can't know which in advance. example of a string i want to match: and the pattern $pattern = '/(\'|")([^\1])(\1)/s'; should match only but doesn't match anything. using $pattern = '/(\'|")(.*)(\1)/s'; matches which is not what i want
  3. the problem is that doesn't work. i'm trying to get the contents of a string delimited by either double quotes ("...") or single quotes ('...'). the regex i'm using is: $pattern = '/(\'|")([^\1]*)(?:\1)/s' that doesn't work. however, changing it to $pattern = '/(\'|")([^\']*)(?:\1)/s' does work (assuming the string is delimited by single quotes). i checked and made sure that \1 contains a single or double quote (used preg_match() with the optional &$matches argument and print_r()'ed $matches to see what is in the sub-patterns). as a result, i assume either i can't use a backreference in a character class or i'm doing something wrong.
  4. regular expressions http://www.phpfreaks.com/tutorial/regular-expressions-part1---basic-syntax or if the string inside which the substring you want is static (always the same) you could use strcmp (case sensitive), strcasecmp (case insensitive), substr, strstr or something similar (chack out the functions on this page http://us2.php.net/manual/en/book.strings.php.
  5. hi all how would i go about using a backreference in a character class in a pcre regex pattern? example of something similar to what i want to do: $pattern = '/(abc)([^\1]).*/'; thanks in advance bob
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.