2

I have the followign Regex:

/(?<=SOMEMETHOD\(|\G)\s*((['"]).+?(?<!\\)\2|\{[^}]+\}|[^,;'"(){}\)]+)\s*(?:,|\))/g

I tested it on IRC #Regex, and it works.

!regex (function() { new SOMEMETHOD('Parameter 1','parameter2',{"json1":0,"json2":14962,"json3":false,"json4":'hej'},lastparameter); morecode(); ests sts st /(?<=SOMEMETHOD(|\G)\s*((['"]).+?(?

[Result: 4] [0:-?: ] [1:90-102: 'Parameter 1'] [2:90-90: '] [3:104-115: 'parameter2'] [4:104-104: '] [5:117-169: {"json1":0,"json2":14962,"json3":false,"json4":'hej'}] [6:171-183: lastparameter]

It dont work in .net though:

        string pattern = @"/(?<=SOMEMETHOD\(|\G)\s*((['""]).+?(?<!\\)\2|\{[^}]+\}|[^,;'""(){}\)]+)\s*(?:,|\))/g";

        var t = Regex.Match(e.Document, pattern);

I dont know if its an escaping problem of some chars.

1
  • In what way doesn't it work, what specific error are you getting? No matches? Exception? Commented Jul 31, 2011 at 22:50

1 Answer 1

2

The pattern shouldn't contain the / at the beginning and the /g at the end. That is the syntax for declaring a literal regular expression object.

string pattern = @"(?<=SOMEMETHOD\(|\G)\s*((['""]).+?(?<!\\)\2|\{[^}]+\}|[^,;'""(){}\)]+)\s*(?:,|\))";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.