So, what does next regexp actually mean?
str_([^_]*)(_[_0-9a-z]*)?
And is it equal to ^str_[^_]*(_[_0-9a-z]*)??
str_ matches these characters literally
([^_]*) matches any character 0 or more times that is not a underscore
(_[_0-9a-z]*)? matches another underscore and then 0 or more of the characters _0-9a-z. This last part is optional.
I wrote recently a really brief regex introduction, hope it will help you..
As mentioned in the comments to my answer, http://gskinner.com/RegExr/ explains everything about a regular expression if you put it in.
str_([^_]*)(_[_0-9a-z]*)?
\ /^\ /^^^^\ /^^^
\/ | \/ |||| \ / |||
| | | |||| \ / ||`- Previous group is optional
| | | |||| \ / |`-- End second capture group (an underscore and any amount of characters _, 0-9 or a-z)
| | | |||| | `--- Match any amount (0-infinite) of previous (any character _, 0-9 or a-z)
| | | |||| `-------- Match any of the characters inside brackets
| | | |||| (0-9 means any number between 0 and 9, a-z means any lower case char between a and z)
| | | |||`------------- Match "_" literally
| | | ||`-------------- Start second capture group
| | | |`--------------- End first capture group (any amount of any character which is not underscore)
| | | `---------------- Match any amount (0-infinite) of previous (any character which is not underscore)
| | `------------------- ^ at the start inside [] means match any character not after ^
| | (In this case, match any which is not underscore)
| `--------------------- Start first capture group
`------------------------ Match "str_" literally
The ^ at the start of ^str_[^_]*(_[_0-9a-z]*)? just means that it should only match at the start of line of anything you input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With