M
M
Max Maximov2016-05-15 15:57:49
Parsing
Max Maximov, 2016-05-15 15:57:49

How to write a regular expression for text?

Hello.
I have no experience in regular expressions, so the next question is:
there is a huge database consisting of records of a certain format ( Date | Credit-Debit | Description ). I need to pull out all these three data. And in the process of this, immediately determine what is Credit or Debit: Credit is located in the middle , debit is on the right .
Source example: pastebin.com/vL3GZqsN

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2016-05-15
@maximka19

/(.*)\|[\s\t]+[\s\t]+([0-9.,-]+(([\t\s]+)|))\|(.*)/gu

https://regex101.com/r/xG8mU5/3
By groups of occurrences:
1st: DATE
2nd: AMOUNT
3rd: check: non-empty - means CREDIT, otherwise - DEBIT.
4th: DESCRIPTION

V
Vladimir Kuts, 2016-05-15
@fox_12

Well Duc and what will you parse? Your string miraculously beats on the symbol '| by three elements' at least with the same regular expression "^(.*?)\|(.*?)\|(.*?)$".
If there are no gaps in the middle element on the right, then this is a debit, if there is, a credit. You can check for the last character...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question