-4

Problem: in short the question is how to use back reference when the brackets are nested in each other. Example I have a the following:

213.321
.323
213.

It must match every real number with decimal point.It must not match wait any I have this regex which works for me!

(()|([0-9]+)).(()|([0-9]+))

But I want to back reference to the OUTER bracket.

We see there are three bracket, so we can use the following back reference \1 or \2 or \3.

But really I want to back reference to the outer bracket.How it us possible to do or it is impossible to do ?

Also, if trying to use \1 or \2 or \3 it not works.

Zsombi
  • 72
  • 1
  • 8
  • 2
    Please [edit] your question to show us a specific example of what you're trying to do. At the moment, it is unclear. – Tom Fenech Jan 16 '17 at 15:15
  • Can you include full example? For your example `\d+\.\d+` is enough. – Mohammad Yusuf Jan 16 '17 at 15:43
  • match groups are counted each time a left paren is encountered. so for a nested set for example: `((second)first(last))` – Scott Weaver Jan 16 '17 at 15:43
  • using \1 doesn't provide solution ^(()|([0-9]+))\.\1 – Zsombi Jan 16 '17 at 15:58
  • The outer bracket IS `\1`. Clarify your question with concise, testable sample input and expected output, a better explanation of what you're trying to do, and details about in what way using `\1` "doesn't provide solution" - wrong output, no output, error messages, core dump, something else? Also tell us which version of `egrep` you are using (and stop using it is it's deprecated, use `grep -E` instead). – Ed Morton Jan 16 '17 at 16:57

1 Answers1

0

In your regular expression (()|([0-9]+)).(()|([0-9]+)), the following are the the various groups:

(()|([0-9]+)).(()|([0-9]+))
12  3         45  6

Both \2 and \5 will always be empty. The outer groups are referenced by \1 and \4.

Kusalananda
  • 12,623
  • 3
  • 33
  • 46