0

i have a bunch of calls in a repo of code like this:

$out = $this->call('myApp.Settings.Menus.something.doSomething', $input);

I'd like to find all instances of it using regex where the first param of $this->call() contains only 1 period.

i'm getting closer, i think, with this: (?=\$this->call\(')(\.){1}(?=',)

Why isn't it limited to 1 period?

2
  • How do you apply that regex (which engine, which flags, which anchors)? Commented Oct 30, 2012 at 23:21
  • i'm doing a regex code search in neatbeans, actually Commented Oct 30, 2012 at 23:22

3 Answers 3

2

What you're looking for is a simple:

 '[^.]+?[.][^.]+?'

Which means any number of non-dots, folled by a dot, and some non-dots again.

Better yet, be a bit more precise:

  '\w+?([.]\w+?)?'

This matches alphanumeric characters, and a dot. Second half (optional)?.

(Your (\.){1} would just match a single period.)

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

3 Comments

I'm trying to exclude results containing more than 1 dot.
Then make the second half ( optional )? as well.
which part are you calling the second half?
1

The following should work, namespace will be in the first capture group:

\$this->call\('([^'.]*\.[^'.]*)',

If you want to use a lookbehind/lookahead so that the namespace is the only part of the string matched by the regex, you can use the following:

(?<=\$this->call\(')[^'.]*\.[^'.]*(?=',)

Comments

0

This is a safe regex:

\$this\s*\-\>\s*call\s*\(\s*[\'\"]\.[\'\"]

It accounts for whitespaces between language characters like:

$this ->   call ( '.'

where it is still technically correct syntax. Additionally this is indifferent to single or double quoted string as teh first parameter.

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.