kb:zapisi:regex_main

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
kb:zapisi:regex_main [2023/08/15 14:26] – [Intermediate topics] milanokb:zapisi:regex_main [2023/08/16 09:11] (current) – [Pogled napred i pogled iza — (?=) i (?<=)] milano
Line 30: Line 30:
 ===== ILI operater — | ili [] ===== ===== ILI operater — | ili [] =====
  
-''a(b|c)'' odgovara nizu koji ima **a** praćeno sa **b** //ili// **c**+''a(b|c)'' odgovara nizu koji ima **a** praćeno sa **b** //ili// **c** \\
 ''a[bc]'' isto kao i prethodni ''a[bc]'' isto kao i prethodni
  
Line 77: Line 77:
 ====== Međuteme ====== ====== Međuteme ======
  
-===== Grouping and capturing — () =====+===== Grupisanje i hvatanje — () =====
  
-''a(bc)'' parentheses create a //capturing group// with value **bc** \\ +Zagrade ''a(bc)'' stvaraju //grupu za snimanje// sa vrednošću **bc** \\ 
-''a(?:bc)*****'' using ''?:''  we disable the capturing group **bc** \\ +''a(?:bc)*****'' koristeći ''?:''  onemogućavamo grupu za snimanje **bc** \\ 
-''a(?<foo>bc)'' using ''?<foo>'' we put a name to the group **bc** \\+''a(?<foo>bc)'' koristeći ''?<foo>'' dali smo ime grupi **bc** \\
  
-This operator is very useful when we need to extract information from strings or data using your preferred programming languageAny multiple occurrences captured by several groups will be exposed in the form of a classical arraywe will access their values specifying using an index on the result of the match.+Ovaj operator je veoma koristan kada treba da izvučemo informacije iz nizova ili podataka koristeći željeni programski jezikSvako višestruko pojavljivanje koje uhvati nekoliko grupa biće izloženo u obliku klasičnog nizapristupićemo njihovim vrednostima specificirajući pomoću indeksa na rezultatu podudaranja.
  
-If we choose to put a name to the groups (using ''(?<foo>…)''we will be able to retrieve the group values using the match result like a dictionary where the keys will be the name of each group.+Ako odlučimo da damo ime grupama (koristeći ''(?<foo>…)''), moći ćemo da preuzmemo vrednosti grupe koristeći rezultat podudaranja kao rečnik gde će ključevi biti ime svake grupe .
  
-===== Bracket expressions — [] =====+===== Izrazi zagrade — [] =====
  
-''[abc]'' matches a string that has **either an a or a b or a c** is the **same as a|b|c ** \\ +''[abc]'' podudara se sa nizom koji ima **ili ili ili c** koje je **isto kao a|b|c ** \\ 
-''[a-c]'' same as previous \\ +''[a-c]'' isto kao i prethodni \\ 
-''[a-fA-F0-9]'' a string that represents **a single hexadecimal digitcase insensitively** \\ +''[a-fA-F0-9]'' niz koji predstavlja **jednu heksadecimalnu cifrubez obzira na velika i mala slova** \\ 
-''[0-9]%'' a string that has a character **from to before a sign** \\ +''[0-9]%'' niz koji ima karakter **od do pre znaka %** \\ 
-''[^a-zA-Z]''string that has not a letter from a to or from to Z. In this case the ''^''  is used as **negation of the expression** \\ \\+''[^a-zA-Z]'' niz koji nema slovo od do ili od do Z. U ovom slučaju se ''^'' koristi kao **negacija izraza** \\ \\
  
-Remember that inside bracket expressions all special characters (including the backslash lose their special powersthus we will not apply the escape rule”.+Imajte na umu da svi posebni znakovi unutar izraza u zagradama (uključujući obrnutu kosu crtu​​gube svoja posebna ovlašćenjastoga nećemo primeniti „pravilo bežanja“.
  
-===== Greedy and Lazy match =====+===== Pohlepni i lenji se poklapaju =====
  
-The quantifiers ( ''* + {}''are *greedy operators*, so they expand the match as far as they can through the provided text.+Kvantifikatori ( ''* + {}''su *pohlepni operatori*, tako da proširuju podudaranje koliko god mogu kroz dati tekst.
  
-For example, ''<.+>''  matches ''<nowiki><div>simple div</div></nowiki>''  in ''This is a <nowiki><div>simple div</div></nowiki>'' test. In order to catch only the ''div''  tag we can use a ''?''  to make it lazy \\ +Na primer, ''<.+>'' odgovara ''<nowiki><div>simple div</div></nowiki>''  ''This is a <nowiki><div>simple div</div></nowiki>'' test. Da bismo uhvatili samo oznaku ''div'', možemo koristiti ''?'' da je učinimo lenjim \\ 
-''<.+?>'' matches any character **one or more** times included inside ''<'' and ''>'', **expanding as needed**. \\+''<.+?>'' podudara se sa bilo kojim znakom **jedan ili više** puta uključenim unutar ''<'' ''>'', **proširujući po potrebi**. \\
  
-Notice that a better solution should avoid the usage of ''.''  in favor of a more strict regex+Primetite da bi bolje rešenje trebalo da izbegava upotrebu ''.'' u korist strožijeg redovnog izraza
-''<[^<>]+>'' matches any character except ''<'' or ''>'' one or more times included inside ''<''  and ''>''.+''<[^<>]+>'' odgovara bilo kom znaku osim ''<'' ili ''>'' jednom ili više puta uključenim unutar ''<'' ''>''.
  
 ---- ----
  
-====== Advanced topics ======+====== Napredne teme ======
  
-===== Boundaries — b and B ===== +===== Granice — b B ===== 
-''\babc\b'' performs a **"whole words only"** search \\ \\+''\babc\b'' vrši **"samo cele reči"** pretragu \\ \\
  
-''\b''  represents an **anchor like caret**  (it is similar to ''$''  and ''^''matching positions where **one side** is a word character  (like ''\w''and the **other side** is not a word character  (for instance it may be the beginning of the string or a space character).+''\b'' predstavlja **sidro kao karet** (slično je kao ''$'' ''^''odgovarajućim pozicijama gde je **jedna strana** karakter reči (kao ''v''), a **druga strana** nije karakter reči (na primer, može biti početak stringa ili razmak).
  
-It comes with its **negation**, ''\B''This matches all positions where ''\b''  doesn’t match and could be if we want to find a search pattern fully surrounded by word characters+Dolazi sa svojom **negacijom**, ''\B''Ovo se poklapa sa svim pozicijama na kojima se ''\b'' ne podudara i može biti ako želimo da pronađemo obrazac pretrage u potpunosti okružen znakovima reči
-''\Babc\B'' matches only if the pattern is **fully surrounded** by word characters.+''\Babc\B'' se podudara samo ako je obrazac **potpuno okružen** znakovima reči. 
 +===== Povratne reference — 1 =====
  
-===== Back-references — =====+''([abc])\1'' koristeći ''\1'' odgovara **istom** tekstu koji je upario **prva grupa za snimanje**. \\ 
 +''([abc])([de])\2\1'' možemo da koristimo ''\2'' (3, 4, itd.) da identifikujemo **isti** tekst koji je **podudarala druga** (treća, četvrta, itd.) grupa za snimanje. \\ 
 +''(?<foo>[abc])\k<foo>'' grupi stavljamo ime ''foo'' i referenciramo ga kasnije (''k<foo>''). Rezultat je isti kao prvi regularni izraz.
  
-''([abc])\1'' using ''\1''  it matches **the same** text that was matched by the **first capturing group**. \\ 
-''([abc])([de])\2\1'' we can use ''\2''  (3, 4, etc.) to identify **the same** text that **was matched by the second** (third, fourth, etc.) capturing group. \\ 
-''(?<foo>[abc])\k<foo>'' we put the name ''foo'' to the group and we reference it later (''k<foo>''). The result is the same of the first regex. 
  
 +===== Pogled napred i pogled iza — (?=) i (?<=) =====
 +''d(?=r)'' odgovara „d“ samo ako ga **prati r**, ali „r“ neće biti deo ukupnog podudaranja regularnog izraza. \\
 +''(?<=r)d'' odgovara „d“ samo ako mu **prethodi r**, ali r neće biti deo ukupnog podudaranja regularnog izraza. \\
  
-===== Look-ahead and Look-behind — (?=) and (?<=) ===== +Možete koristiti i operator negacije!
-''d(?=r)'' matches a ''d'' only if it is **followed by r**, but ''r'' will not be part of the overall regex match. \\ +
-''(?<=r)d'' matches a ''d'' only if it is **preceded by an r**, but r will not be part of the overall regex match. \\ +
- +
-You can use also the negation operator! +
- +
-''d(?!r)'' matches a ''d'' only if is **not followed by r**, but r will not be part of the overall regex match. \\ +
-''(?<!r)d'' matches a ''d'' only if is **not preceded by an r**, but r will not be part of the overall regex match.+
  
 +''d(?!r)'' odgovara „d“ samo ako **ne prati r**, ali r neće biti deo ukupnog podudaranja regularnog izraza. \\
 +''(?<!r)d'' odgovara „d“ samo ako mu **ne prethodi r**, ali r neće biti deo ukupnog podudaranja regularnog izraza.
  • kb/zapisi/regex_main.1692109569.txt.gz
  • Last modified: 2023/08/15 14:26
  • by milano