How the positive sign and the data outside the matching bracket Expression

This article introduces the regular expression matching symbols and data outside the brackets, very good, has a certain value for references, you can refer a friend in need

Regular expression matching symbol outside the parentheses

[\\?!/\\.,\\s]+(?=[^\\)]*(\\(|$))

The outer parentheses?! /., And spaces (continuous multiple simultaneously) match

Such as

String string1 = "sdfsdf sdlfksd sdf,fsdf&sdf(s:1,g:1) sdfsd sdf! ? . sdfl asdf ";
String[] str = string1.split("[\\?!/\\.,\\s]+(?=[^\\)]*(\\(|$))");
for(String s:str){
 System.out.println(s);

result:

sdfsdf
sdlfksd
sdf
fsdf&sdf(s:1,g:1)
sdfsd
sdf
sdfl
asdf

The following regular expression matching look data outside the parentheses

Data in parentheses is positive matching, the more easily achieved, but the matching data outside the parentheses, e.g. seemingly more difficult:

"{controller}/cc/{action}/{id}"

I want / cc /, / two data outside the parentheses.

If matching data in brackets (including brackets), this can be achieved with this regular

/{[^}]+}/

Test code (javascript realization):

"{controller}/cc/{action}/{id}".replace(/{[^}]+}/ g,'-')

But to extract the contents outside the parentheses, very difficult ah do not know who can achieve this demand?

Several special strings:

" {Controller} / CC / {Action} / {ID}} "    matches the empty string
 " {Controller}} / CC / {Action} / {ID} "   matched:} / cc /, /

 

 

 

Guess you like

Origin www.cnblogs.com/jb1352461/p/11126975.html