Regex Regular Cro

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Regular Expressions Anchors

Regular Expressions Quantifiers * + ? {3} {3,} {3,5} 0 ili vie 1 ili vie 0 ili 1 tono 3 3 ili vie 3, 4 ili 5

Regular Expressions Groups and Ranges . (a|b) (...) (?:...) [abc] [^abc] [a-q] [A-Q] svi znakovi osim novog reda (\n) a ili b grupa pasivna (ne-varijabilna) grupa rang (a ili b ili c) Sve osim a ili b ili c Slova (kurentna) od a do q velika (verzalna) slova od A do Q digitalne znamenke od 0 do 7 nth group/subpattern

^ poetak stringa,odn. poetak retka \A $ poetak stringa kraj stringa, odnosno kraj reda

\Z zavretak stringa \b graninik rijei \B nije rije \< Poetak rijei \> Kraj rijei

? uvijet da se neto ne pojavljuje ili se pojavljuje jednom


Regular Expressions Escape Sequences

[0-7] \n

Regular Expressions Character Classes

\ \Q \E

Prespojni znak Poetak reenice Kraj reenice

\c \s \S \d \D \w \W \x \O

Control character razmaknica \ space Not white space Digit [0-9] Not digit Word [a-zA-Z0-9_] Not word Hexadecimal digit Octal digit

ako se umetne .* biti e svi znakovi do novog reda


Regular Expressions Pattern Modifiers g i m s x e U Global match Case-insensitive Multiple lines Treat string as single line Allow comments and white space in pattern Evaluate replacement Ungreedy pattern

"Escaping" is a way of treating characters which have a special meaning in regular expressions literally, rather than as special characters. Regular Expression Common Metacharacters

^ $ ( ) <

[ { \ | >

. * + ?

Regular Expressions POSIX

[:upper:] [:lower:] [:alpha:] [:alnum:] [:digit:] [:xdigit:] [:punct:] [:blank:] [:space:] [:cntrl:] [:graph:] [:print:] [:word:]

Upper case letters Lower case letters All letters Digits and letters Digits Hexadecimal digits Punctuation Space and tab Blank characters Control characters Printed characters Printed characters and spaces Digits, letters and underscore

Regular Expressions String Replacement $n $2 $1 $` $' $+ $& nth non-passive group "xyz" in /^(abc(xyz))$/ "xyz" in /^(?:abc)(xyz)$/ Before matched string After matched string Last matched string Entire matched string

Prespojni znak je obino backslash - \.


Regular Expressions Special Characters

\n \r \t \v \f \xxx xxx\xhh hh

New line Carriage return Tab Vertical tab Form feed Octal character Hex character

Some regex implementations use \ instead of $.

Regularno

Ostalo

(?i) (?m) \b [^] [A-z] \t \r\n (?x)

ukljuuje neosjetljivost (A - a B - b) line by line - vieredanost granica rijei ^ i $ - granica retka

(?<naziv>100)(?P=naziv) ${naziv}

referencija

Regular Expressions Assertions ?= ?! ? = ?!= or ? ! < ?> ?() ?()| ?# Lookahead assertion Negative lookahead Lookbehind assertion Negative lookbehind Once-only Subexpression Condition [if then] Condition [if then else] Comment

(?i)word(?-i) granica neosjetljivosti \w = [A-Za-z0-9_] neprazni znakovi (string) negacija - mora biti u kalasi velika i mala slova, ali i [ ] \ ' _ ^ tabulator (tab) novi odlomak (redak - ) u W, n (Unix), r (mac os) free spacing; ignorira razmake; ako elimo pisati regularni izraz u vie redaka

imenovana grupa u zamjeni

(?=neto) Gledanje unaprijed (pozitivno) (?!neto) Gledanje unaprijed (negativno) (?<=neto) Gledanje unazad (pozitivno) (?<!neto) Gledanje unazad (negativno)
(?=[x1y1])\d{x} definiranje onoga to slijedi Uinimo lakomi + lijeni: <.+?> ime kaemo im zadovolji uvjet, zaustavi traenje i kreni dalje (prije operatora)

.*(house).* u tom redu

Ostalo

(red)(green)(blue)\1\2\3 varijable (referenciranje) . (?:[123456789]) pasivna grupa vie nije varijabla . (?s) - proiruje znaenje toke koja inae oznaava sve znakove osim retka

You might also like