#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Unhappy Convert C# RegEx to Java RegEx


    Hi all;
    I have some RegEx in C#, and i would like use them in java Application, but the c# and Java RegEx are not compatible, so it does a RegEx converter exist?; for more ingo my RegExs are:
    (".*?[^\\]")|('.*?[^\\]')|<<<(\w+)(.|\s)+?(\4)
    \$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
    (?<=function[\s+])[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?=\s*\()
    (?<![$])(?<=[\s=\+\-\*\(\)\!\>,;@])[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*(?=\s*\()
    (?<=class\s)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

    Thank you; i have realy need to this.
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    Because Java regexps have to be contained in a String, you need to double your backslashes.

    e.g. to match whitespace, put in \\s
    to escape a bracket, it's \\]
    for a literal backslash character, you need \\\\
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Unhappy I must replace \ by \\??


    hy; thanks for your answer; but i haven't understand you; what i should do, i sould replace \ by \\; i have try this, but i have an error whene i execute the program.

    Thanks.
  6. #4
  7. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    What's the error? And what does your regexp look like now?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Red face Error whene creating the Pattern


    Hi, the error that i have, is in the creation of the pattern, i m in the ofiice now, and this project is at home, i will post the error to night;
    For the new RegEx, it's exactly the first one, but i have just replace \ with \\, i have not modify the rest.
    Are you sure that is the only changes that i have to do??
    Thanks for you.
  10. #6
  11. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    You'll also have to escape the double-quotes you have in your pattern by placing a single backslash before them.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Unhappy It don work!!


    Hi, i have modify my regex but they still dont working the error is :
    java.lang.IllegalStateException: No match found
    and it happens whene i try to do this
    MyMacherObject.groupe(indexGroup);
    it is stange because whene i try this
    MyMacherObject.groupCount(); it render me '5' in my case, so it is not null;
    ????
    So; i think that the content of myMatcherObject is not cerrect; and this is due to my regEx.

    Thanks.
  14. #8
  15. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    What does your regexp look like now?

    And what data are you applying it to?

    Preferably post these as executable Java code. Thanks.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Unhappy My new regex!


    hi; and thanks for all your answers.
    the first regex that my program exécute is:
    (\".*?[^\\\\]\")|('.*?[^\\\\]')|<<<(\\w+)(.|\\s)+?(\\4)
    and i applay this regex to this string:
    "<?php
    function nettoyerSource($suppcom, $destination)
    {
    $dossier=dirname($destination);
    if(!file_exists($dossier)) mkdir($dossier, '0777', true);
    $code=php_strip($suppcom);
    $ecriture=file_put_contents($destination, $code);
    return (bool) $ecriture;
    }
    $succes=nettoyerSource('/dossier1/source.php', '/dossier2/destination.php');
    ?>"
    the program that i develope is an application that obfuscate php code.
    the rest of reges is not exécuted because the the first one bugs; so i have not send the rest of regex.

    Thanks a lot.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    6
    Rep Power
    0

    Smile Resolved


    Problem resolved, the regex were correct, i have doing some errors whene copying and pasting;

    Thank you for all our answers.

IMN logo majestic logo threadwatch logo seochat tools logo