FANDOM


Regex Question Edit

I'm new to regex in vim, so I have a couple questions. Why does the pattern have \(\(\w\)\(\w\+\)\) instead of something simpler like \(.*\)? Is this to check for duplicates of the same word? Woulnd't that be out of the scope of this page? Also, how does the \u\2\3 work? Wouldn't replacing that with \1 be simpler and easier to understand? Also, this should be generalized no? NOt specific to PHP.

Just ".*" won't work because it matches everything in the line, so the tip author limited matches to just "word" characters using \w. A better choice would probably be "keyword" characters \k. I think you're correct that the weird nested capture groups are not necessary, the author may have thought it necessary to capture the first character separately for the \u to work (capitalizing the next letter). However that is not required, probably a simple \k+ and \1 in the substitute could work just as well. --Fritzophrenic (talk) 17:14, September 21, 2016 (UTC)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.