0

I am trying to use regular expression to parse command line argument. Now, for this specific type of command line argument the user have the flexibility to enter the string in either of these forms:

[Cent_acc_00.txt, Cent_acc_00.txt, 0.02, cm/s2, 20, 120]

[Cent_acc_00, Cent_acc_00, 0.02, cm/s2, 20]

The regular expression command that I have used is:

eq_2 = re.findall("\[[\w\-\.]+[txtcsv\S], [\w\-\.]+[txtcsv\S], [0-9\.]+, [\w/]+, [0-9\.]+([,\s]+[0-9\.]+|)]",eq)

It's showing correctly in regular expression search bar in VS code, however, it is failing to match while used in python.

naseefo
  • 720
  • 1
  • 9
  • 30
  • `[txtcsv\S]` What are you trying to do there? Why not just use `\S` to match any non-whitespace character? (or, if you only want `txt` / `csv`, use alternation, not a character set) – CertainPerformance Jan 27 '19 at 21:35
  • I was considering that the user should be able to use Cent_acc_00.txt or Cent_acc_00.csv or Cent_acc_00 (with default being *.txt) – naseefo Jan 27 '19 at 21:38
  • Replace `(....)` with `(?:...)` – Wiktor Stribiżew Jan 27 '19 at 22:01
  • Do you mean for the last term: (?:[,\s]+[0-9\.]+|) But it's still not giving the intended result. I am getting the output as [('t','t')] – naseefo Jan 27 '19 at 22:10

0 Answers0