search string using case sensitive

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • epots9
    Recognized Expert Top Contributor
    • May 2007
    • 1352

    search string using case sensitive

    sorry in advance, i'm just tried..

    ok, i need to search a string for something and i want it to return the location of where in the string it is (like the function strpos()), but i need to know the location of where a lowercase letter is immediately followed (no space, no thing between) by a uppercase letter.

    I have a feeling it has to done using regular expressions (not sure), and i'm not the greatest at those right now....

    open to all suggestions,

    Thank You.
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    Originally posted by epots9
    sorry in advance, i'm just tried..

    ok, i need to search a string for something and i want it to return the location of where in the string it is (like the function strpos()), but i need to know the location of where a lowercase letter is immediately followed (no space, no thing between) by a uppercase letter.

    I have a feeling it has to done using regular expressions (not sure), and i'm not the greatest at those right now....

    open to all suggestions,

    Thank You.
    Ideal here
    use

    strtolower() function to convert everything in lower case
    then use ucfist() to convert the first letter in a string as an upper case.

    You will know that the second letter is in lower case.
    nomad

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Originally posted by epots9
      ok, i need to search a string for something and i want it to return the location of where in the string it is (like the function strpos()), but i need to know the location of where a lowercase letter is immediately followed (no space, no thing between) by a uppercase letter.
      Regular expressions unfortunately won't help a whole lot because there's no preg_pos function. But you can do this:

      [code=php]
      $array = preg_split('/[a-z][A-Z]/', $string, 1);
      if(empty($array[1]))
      // Not found
      else
      $offset = strlen($array[0]);
      [/code]

      If your $string were '012345nG89' (expected return value will be 6), then preg_split would divide the string into:

      [code=php]
      array(
      0 => '012345'
      1 => '89'
      )
      [/code]

      If you strlen() the 0th element of that array, you get 6.

      [EDIT: Not sure if $array[1] will be set if the target pattern is at the end of the string (e.g., '012345nG').]

      Comment

      • epots9
        Recognized Expert Top Contributor
        • May 2007
        • 1352

        #4
        thank you, thats what i needed

        Comment

        • sandyw
          New Member
          • Mar 2007
          • 122

          #5
          Originally posted by epots9
          sorry in advance, i'm just tried..

          ok, i need to search a string for something and i want it to return the location of where in the string it is (like the function strpos()), but i need to know the location of where a lowercase letter is immediately followed (no space, no thing between) by a uppercase letter.

          I have a feeling it has to done using regular expressions (not sure), and i'm not the greatest at those right now....

          open to all suggestions,

          Thank You.
          which tread do you use to solve the problem?
          sandy

          Comment

          • epots9
            Recognized Expert Top Contributor
            • May 2007
            • 1352

            #6
            Originally posted by sandyw
            which tread do you use to solve the problem?
            sandy
            i used pbmods's suggestion

            Comment

            Working...