List Info

Thread: nested brackets with javascript




nested brackets with javascript
user name
2006-03-04 16:15:16
SUMMARIZING....

(\w+{)
  (
    {(?<DEPTH>)
    |
    }(?<-DEPTH>)
    |
    .*?
   )*
   (?(DEPTH)(?!))
(})

Options: RegexOptions.IgnoreCase
    | RegexOptions.Singleline
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );


WHAT IT DOES?: matches recursively 2 resourceType{.....} blocks
from

input:

resourceType{
field1 = aValue,
field2 = "value with quotation marks",
field3 = "value with quotation mark and  in
the field value",

field4 = ,
lastfield = "should not have a delimiting comma, but
some generators do

anyhow"
}

{some other HTML code}

resourceType{
field1 = aValue,
field2 = "value with quotation marks",
field3 = "value with quotation mark and
 in the field
value",
field4 = ,
lastfield = "should not have a delimiting comma, but
some generators do

anyhow" 
} 
}
{some other HTML code}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

nested brackets with javascript
user name
2006-03-04 17:11:30
Dear Sergej, Allen,

wow, just went out for a coffee and 5 re:s already! Thanks a
lot
already.
After a brief glance at the balancing .NET stuff I am very
impressed
(almost reminds me of real lex/yacc tokens)
Unfortunatly this is not an option for me (bound to
javascript).
The other thing is, that my problem is even simpler:
recursive nesting
does not happen, so its at most  (one level
'deep' inside
the outer most { } pair.

So to reformulate:
I am trying to ignore {} pairs inside an outer pattern
delimited by
[\s\S]+?{  on the one end and } at the other

Thanks a lot for your fast and valuable input
Cheers
Tyler


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

nested brackets with javascript
user name
2006-03-04 18:56:02
Re: ***So to reformulate:
I am trying to ignore {} pairs inside an outer pattern
delimited by
[\s\S]+?{  on the one end and } at the other***

that's exactly the problem u r facing:

how would u distinguish between the last closing bracket of
the
resourceType{ .......} block AND any of the INNER
brackets? It IS
RECURSIVE, man. The only difference between the last closing
bracket
and the rest of "inner" brackets inside the
block is that they are
logically linked (i.e. they form a open-close pair). This
logic is
impossible to implement by simple lookaround assertion,
simply because
u dont know how many inner bracket pairs u can have inside.
And this is
despite of them being on "the first layer deep".
U need either

1. to use a recursuve regex solution above or
2. implement your own recursive parser (DOM?)

Can anyine prove me wrong? I'd be very interested in
feedback on this.

PS: Tyler, why doesn't ****** look recursive to
u? It's 1
level deep but it is recursive.

Sergei


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

nested brackets with javascript
user name
2006-03-04 19:26:21
these ugly thing has a [very slim] chance to retrieve your
strings
non-recursively,

\w+{(.*?{.*?})+.*?}(?=.*?\w+)

but

1. there MUST be inner curly brackets  for this to work
and
2. it uses variable look-ahead to find .*?\w+
after the last closing
bracket. So, the chances are that it'll break if encounters
something
similar to  \w+ at some point ahead of the desired input
fragment like

resourceType{
field3 = "value with 
field4 = 
smth else
}

3. it will not match the last desired code fragment in the
input (u can
tweak it to handle this, i guess)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

nested brackets with javascript
user name
2006-03-04 23:29:48
But only one level of recursion, so what about this:

[^{]+{([^{}]|{[^{}]*})*}

Works only, if
- braces are always balanced
- no braces in strings present
- level of brace nesting is only one


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

nested brackets with javascript
user name
2006-03-05 11:31:27
Torsten,

this is excellent. It looks a bit like black magic, but it
really does
the job!

Thanks to all of you for your input, 'twas enlighting!

Have a nice weekend, 
Tyler


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )