Reputation: 20322
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\(\);
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
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
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