开发者

Regex for lines from /etc/passwd and /etc/group

开发者 https://www.devze.com 2023-02-24 06:38 出处:网络
I\'ve been working on a small Java problem set and have come across some trouble. I\'m not very experienced writing regular expressions and could really use two for verifying line entries in /etc/grou

I've been working on a small Java problem set and have come across some trouble. I'm not very experienced writing regular expressions and could really use two for verifying line entries in /etc/group and /etc/passwd in Java.

I found Regex Verification of Line in /etc/passwd earlier and have yet to test it, but it looks adaptable for what I need. Could anyone else help in providing a regex string for either file?

I'm looking to verify user-entered passwd and group lines, in java,开发者_如何学Python before writing them out to disk. If not, I'll likely end up tokenizing each piece and running various expensive operations.


Rather than writing a regex you should probably just read the files with Scanner and parse each line with String.split(":"). Then you can check that each part is valid without dealing with a complex expression to handle all cases. It'll probably be easier to write the code and easier to read it later.


Why do you want to use regular expressions? Just split the line on the colons and inspect the pieces.

0

精彩评论

暂无评论...
验证码 换一张
取 消