Regex help

Discussion in 'PHP' started by andytan91, Aug 3, 2010.

  1. #1
    Hi guys i am trying to regex this string whereby i could change the digit at the "0" part. The requirement is that i only want the number 1. findstr to change digit when regex is carried out and not number 2 as they are in the same text file....thanks in advance!!


    1.findstr /i /C:"LSAAnonymousNameLookup = 0" C:\major_security_settings1.txt
    2.findstr /C:"LSAAnonymousNameLookup = 0" C:\major_security_settings1.txt
     
    andytan91, Aug 3, 2010 IP
  2. flexdex

    flexdex Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Even if your question looks that you didnt try it yourself i will spoonfeed you just to increase my postcount.

    
    $result = preg_replace('%(findstr /i /C:"LSAAnonymousNameLookup = )\d+(" C:\\\\major_security_settings1.txt)%im', '\1$yourNumberHere\2', $subject);
    
    Code (markup):
    
    $subject=<<<SSS
    1.findstr /i /C:"LSAAnonymousNameLookup = 0" C:\major_security_settings1.txt
    2.findstr /C:"LSAAnonymousNameLookup = 0" C:\major_security_settings1.txt 
    SSS;
    
    $result = preg_replace('%(findstr /i /C:"LSAAnonymousNameLookup = )\d+(" C:\\\\major_security_settings1.txt)%im', '\1$yourNumberHere\2', $subject);
    
    echo $result;
    
    Code (markup):
    Have fun and maybe get some education some day!
     
    Last edited: Aug 4, 2010
    flexdex, Aug 4, 2010 IP
  3. andytan91

    andytan91 Greenhorn

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    thanks anyway, actually i have tried for quite long! The problem is that it wont let me replace the digit with the value "0", i tried changing the value of "disabled" to like 2 for example and it works..[0-9] should be able to accept the digit 0 right?

    $batch_contents = preg_replace('~(findstr /i /C:"LSAAnonymousNameLookup = )([0-9])~', '${1}'.$newArgument3, $batch_contents);

    <p>
    <form action="editsecurity.php" method='post'>
    Network Access:Allow Anonymous SID/Name Translation:<select name="SID">
    <option selected=""></option>
    <option value="1">Enable</option>
    <option value="0">Disable</option>
    </select><p>
     
    andytan91, Aug 4, 2010 IP
  4. flexdex

    flexdex Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think its ok to post your previous attempts with your question. So it wont look like you just need your homework done from someone here :)

    Yes, [0-9] matches a digit from 0 to 9 and \d will do the same. I do not get the actual problem. It's solved? have you checked my examples i did for you?
     
    flexdex, Aug 4, 2010 IP
  5. andytan91

    andytan91 Greenhorn

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    alright it works now that i omit out !empty($_POST['SID']) in my if statement..thanks for the help dude
     
    andytan91, Aug 4, 2010 IP