Regular Expression help - simple for someone else, not me

Discussion in 'Programming' started by Neutron, Feb 14, 2008.

  1. #1
    I hope this is the best place to post this question. I need help with using wildcards in a regular expression.

    Using the below example line of code, how do I find cases of $code = 'XXXXXXXX' using a regular expression in source code; regardless of what is between the single quotes? I have many php files that I want to search and they all have that line of code except they differ in what is in the quotes. I want to find them all and insert something else there.

    $code = 'ajvfweibfiuwbviusbvsv';
    Code (markup):
    Thanks for helping the newb
     
    Neutron, Feb 14, 2008 IP
  2. webmaster_TSU

    webmaster_TSU Peon

    Messages:
    449
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If I was searching through a bunch of files, in say Dreamweaver, I think it would be:

    $code = '(.*)';

    I think that's it, but I'm not sure if the $ character would mess up the search or anything.
     
    webmaster_TSU, Feb 14, 2008 IP
  3. Neutron

    Neutron Well-Known Member

    Messages:
    701
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Yes, I use Dreamweaver. What if the code is also broken across multiple lines?

    i.e.

    $code = 'aflshglkjbgadg
                          kasbfiujabfgoauwbgoawg
                          nsdkjgbnaskj';
    Code (markup):
     
    Neutron, Feb 14, 2008 IP
  4. webmaster_TSU

    webmaster_TSU Peon

    Messages:
    449
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Multiple lines is difficult for me to remember...I think to search for everything, even new lines, it's something like (\s|\S)* but I'm not sure how to translate that into what you need. I'm not a pro with reg expressions at all, but I hope that helps a little bit.
     
    webmaster_TSU, Feb 14, 2008 IP
  5. Neutron

    Neutron Well-Known Member

    Messages:
    701
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Thanks. Maybe I should have put this in the php programming category? Hopefully someone stumbles across this and can help. I've tried reading at least a dozen reg exp online tutorials and am lost. I'm certainly no programmer.
     
    Neutron, Feb 14, 2008 IP
  6. Neutron

    Neutron Well-Known Member

    Messages:
    701
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #6
    MODS, could this thread be moved to the php programming section please?
     
    Neutron, Feb 14, 2008 IP
  7. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I don't use dreamweaver but I do know some REGEX in PHP and what webmaster_TSU gave you SHOULD work (in PHP, I'm pretty sure the . character matches even new lines, as it matches any charcter at all).

    However, you might have to escape the $ (by changing it to \$) because in other REGEX, $ means end of line.
     
    zerxer, Feb 15, 2008 IP
  8. lephron

    lephron Active Member

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #8
    . won't match a newline. You can explicitly test for a newline (\n) and whitespace.
     
    lephron, Feb 15, 2008 IP