Black
Black

Reputation: 20322

Notepad++ find string in parantheses

I try to fetch the string modlgn_username inside the paranthesis from the following string:

$this->webDriver->findElement(WebDriverBy::id("modlgn_username"))->click();

This is my regular expression:

\$this->webDriver->findElement\(WebDriverBy::id\("([A-z0-9]+)"\)\)->click\(\);

enter image description here

However I get Find: Can't find text \$this->webDriver->findElement(WebDriverBy::id("([A-Za-z0-9])"))->click();

It works in online regex tester though:

https://regex101.com/r/6oDry3/1

Upvotes: 0

Views: 53

Answers (2)

Toto
Toto

Reputation: 91498

You have to add underscore in the character class or your regex and A-z is not a correct range, it inludes [\]^_ and backquote:

\$this->webDriver->findElement\(WebDriverBy::id\("([A-Za-z0-9_]+)"\)\)->click\(\);

and this character class can be now reduce to \w:

\$this->webDriver->findElement\(WebDriverBy::id\("(\w+)"\)\)->click\(\);

Upvotes: 1

volkinc
volkinc

Reputation: 2128

Your regex will be like this

(?<=\(\")\w+_\w+(?=\"\))

it checks that from left side of the string will be (" and from right side will be ").

It mach the string you need. Have a look

Upvotes: 1

Related Questions