0

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, before writing them out to disk. If not, I'll likely end up tokenizing each piece and running various expensive operations.

Community
  • 1
  • 1

2 Answers2

2

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.

WhiteFang34
  • 70,765
  • 18
  • 106
  • 111
0

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

nobody
  • 19,814
  • 17
  • 56
  • 77