php - Regex to match one or three underscores like "(1_2)_(3_4)" or "(12)_(34)" -


currently regexp used is:

/(^|[\s(])parent_(\w+)_(\w+)\.name/ 

now collides if word match has underscore in it. there easy way handle this?

parent_accounts_accounts.name works

result: accounts accounts

parent_my_module_my_module.name not work

result: my_module_my module

expected: my_module my_module

i think need this:

/\bparent_([a-z]+_?[a-z]+)_([a-z]+_?[a-z]+).name/ig 

or

/\bparent_((([a-z]+_[a-z]+)_([a-z]+_[a-z]+))|(([a-z]+)_([a-z]+)))\.name/ig 

the second 1 checks if first part has _ second part must have too.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -