Back in the late 80's I had a co-worked do exactly this. In those days you could only do things quarterly: change the percentage, change the investment mix, make a withdrawal..
There were no Roth 401K accounts, but contributions could be pre-tax or post-tax. Long term employees were matched 100% up to 8%, newer employees were only matched 50% up to 8% (resulting in 4% match).
Every quarter this employee put in 8%, and then pulled out the previous quarters contribution. The company match continued to grow.
Was it smart? He still ended up with 8% going into the 401K. In those pre-Enron days the law allowed companies to limit the company match to 100% company stock which meant that employees retirement was at risk. Of course by the early 2000's the stock that was purchased for $6 a share was worth $80 a share...
Now what about the IRS:
Since I make designated Roth contributions from after-tax income, can I make tax-free withdrawals from my designated Roth account at any
time?
No, the same restrictions on withdrawals that apply to pre-tax
elective contributions also apply to designated Roth contributions. If
your plan permits distributions from accounts because of hardship, you
may choose to receive a hardship distribution from your designated
Roth account. The hardship distribution will consist of a pro-rata
share of earnings and basis and the earnings portion will be included
in gross income unless you have had the designated Roth account for 5
years and are either disabled or over age 59 ½.
Regarding getting just contributions:
What happens if I take a distribution from my designated Roth account before the end of the 5-taxable-year period?
If you take a distribution from your designated Roth account before
the end of the 5-taxable-year period, it is a nonqualified
distribution. You must include the earnings portion of the
nonqualified distribution in gross income. However, the basis (or
contributions) portion of the nonqualified distribution is not
included in gross income. The basis portion of the distribution is
determined by multiplying the amount of the nonqualified distribution
by the ratio of designated Roth contributions to the total designated
Roth account balance. For example, if a nonqualified distribution of
$5,000 is made from your designated Roth account when the account
consists of $9,400 of designated Roth contributions and $600 of
earnings, the distribution consists of $4,700 of designated Roth
contributions (that are not includible in your gross income) and $300
of earnings (that are includible in your gross income).
See Q&As regarding Rollovers of Designated Roth Contributions, for
additional rules for rolling over both qualified and nonqualified
distributions from designated Roth accounts.