preg expressions in C/C++?



  • Kennt jemand eine Lib in der solche Expressions drin sind um strings zu bearbeiten?

    cYa
    DjR



  • ich hab k.A. was "preg expressions" sein sollen. Wenn du aber Regular Expressions meinst: in boost gibts dafuer eine Lib 🙂



  • das könntes schon sein..
    Naja, hab die boost mal runtergeladen, aber noch nie wirklich genutzt. schau ich mir mal an.
    preg expressions heißen die regulären Ausdrücke, wie sie in perl genutzt werden (und auch in php existieren)



  • Nur soviel, ich hab mir boost diesbezüglich mal angeschaut: die können da schon eine ganze Menge, aber irgendwie gab es da ein paar Einschränkungen.
    Leider ist das zu lange her, so dass ich nicht mehr genau weiß, worin die Unterschiede bestanden.



  • Wofür willst Du die Regexe denn verwenden? Ich habe da mal eine Klasse geschrieben, die sich weitgehend an Perl orientiert, und ein paar Erweiterungen dazu packt. Einschränkung: Backtracking in geklammerte Ausdrücke geht nicht, wenn die schon erfolgreich gematcht sind.
    Nichtkommerzielle Nutzung wäre okay!

    <regular expression> may contain:
           x : matches the character x
           . : matches any single character
           \x : matches x, even if it has a special meaning
           \d : a single digit 0,1,...,9
           \s : 'white space'=blank, tab, return, line feed
           \w : 'word chars'=letters, digits, underscore
           \D : anything except a digit
           \S : anything except white space
           \W : anything except a letter, a digit or an underscore
           \r : a carriage return
           \n : a line feed
           \t : a tab character
           \= : the same character as the one before
           \ooo : (ooo is a 3-digit octal number) the ASCII character ooo
           [x] : the character x
           [^x] : any character except x
           [xyz] : an x, a y or a z
           [d-l] : any character between d and l
           [^a-d] : any character except a, b, c and d
        -> for the next lines, X, Y and Z denote any of the expressions above
           XY : first X, followed by Y
           (XYZ) : X, then Y, and finally Z
        -> for the next lines, X, Y and Z additionally may denote one of the previous two definitions
           X? : X or nothing
           X* : zero to arbitrary Xs
           X+ : one to arbitrary Xs
           X{n} : n Xs in a row
           X{n,m} : n to m Xs in a row
           X{,m} : zero to m Xs
           X{n,} : at least n Xs
           X|Y : either X or Y
           ^X : X, but only at the beginning of a line
           X$ : X, but only at the end of a line
    

Anmelden zum Antworten