Regular expressions - confusion of capture groups

I am reading an Oracle regex tutorial. I am on the topic Capture Groups . Although the link is excellent, except that the bracket is a group, I find many difficulties in understanding the topic. Here are my bewilders.

  • What is the meaning of counting groups in an expression?
  • What does not capture groups?

Developing examples with examples will be enjoyable.

+3
source share
3 answers

Say you have a string, abcabcand you want to find out if the first part of the string matches the second part. You can do this with a single regular expression using capture groups and backlinks. Here is a regular expression that I would use:

(.+)\1

, .+ . , . \1 1 st, , . , , abc. \1 abc, . , , .


. , {...} [...], { } - . ,

{(\d+)}

[\1].

{123} abc {123} 456 123 . \1 123, {(\d+)} abc {123} 456 [\1] abc [123] 456.


, , , , . (xyz)+ , , xyz, , xyzxyzxyz. , xyz+ xy, z, .. xyzzzzz. , , . (?:xyz)+ , (xyz)+, , .

, !

+1
  • , , . . ([abc])([def](\d+)) , , \1, \2 \3. , 3 2. , .
  • , - , , , , 0 , , . , . , .
  • , . . (foo|bar) "foo" "bar". , (: (?:foo|bar) ( )), "" , . , .
  • , , : \b([a-z])[a-z]*\1\b \1 , . , , , .

( - , , .)

: , :

  • ?
  • , group-0, . groupCount() . ?
  • , ?
  • ? ?
+2
  • , , - RegEx.
  • 0 . , groupCount() , .
  • (?:) , . Ex. , : (?:hello|hi there) world! == hello|hi there world. " " " " , "" " " .
  • , , .:) , , .. ^(\d)(?!.*\1)\d+$ , .
+1

All Articles