0

I need to match 2 types of values: 1. Object.Property 2. Object.FuncName("Argument")

For now I try to use something like this: \w+.\w+(\(.*\))? \w+.\w+ - makes sure I get expressions like Object.PropertyName (\(.*\))? - I get any parentheses with arguments inside. As they are wrapped in parentheses and followed by questionmark this part is optional.
So it may be Object.PropName or Object.FuncName('SomeArgHere')

When I use this regex against something like this:
Object.FuncName("SomeArg") = 'SomeValue' AND Object.SomeProp = 'AnotherValue' In regexhero I have 'SomeValue' AND Object matched as well. Instead it should match Object.FuncName("SomeArg") and Object.SomeProp

Based on the answer from I tried to use \w+\.\w+(\(.*?\))?\s+MayContain(\[.+,?\ ?\]) to match against things like: Obj.Prop MayContain["value"] AND Obj.Func("Test") MayContain["Other"]. And it match the whole string, in spite of AND

1 Answer 1

1

You need to escape the dot so that it would match a literal dot otherwise it would match any character other than a newline character.

\b\w+\.\w+(\(.*?\))?

DEMO
IDEONE

Update:

The below regex would match both type of strings,

\w+\.\w+(\(.*?\))?(?:\s+MayContain(\[[^]]*\]))?

DEMO

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, it works! But I tried to use \w+\.\w+(\(.*?\))?\s+MayContain(\[.+,?\ ?\]) based on it to match against things like: Obj.Prop MayContain["value"] AND Obj.Func("Test") MayContain["Other"]. And it match the whole string, in spite of AND. Will update the question.
Exactly what I needed! But what was the problem? It looked like something should be working.
.+ would match any character except \n one or more times.

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.