T
T
tooq2015-12-13 23:40:30
Regular Expressions
tooq, 2015-12-13 23:40:30

How to increase the maximum number of backreferences in regular expressions (sed)?

The crux of the matter is this, there is a long and nasty regular expression I wrote to parse a database of addresses:

s/"([0-9]*)";"((г\. )*(([^ ]*))(( обл\.)|( АО\.)|( Респ\.))*)(, )*((.*) р-н)*(, )*((п\/о\.) ([^,]*))*(, )*(((д\.)|(ж\/д_рзд\.)|(рп\.)|(ж\/д_ст\.)|(ст\.)|(высел\.)|(х\.)|(казарма\.)|(м\.)|(жилрайон\.)|(нп\.)|(снт\.)|(г\.)|(дп\.)|(снт\.)|(п\.)|(пст\.)|(п\/ст\.)|(пгт\.)|(п\/гт\.)|(с\.)|(тер\.)|(массив\.))( [^,]*))*(, )*(((д\.)|(ж\/д_рзд\.)(снт\.)|(г\.)|(дп\.)|(нп\.)|(мкр\.)|(жилзона\.)|(снт\.)|(п\.)|(пст\.)|(п\/ст\.)|(пгт\.)|(п\/гт\.)|(с\.)|(тер\.)|(массив\.))( [^,]*))*(, )*((.* )((ул\.)|(пер\.)|(наб\.)|(ш\.)|(линия\.)|(казарма\.)|(б-р\.)|(тер\.)|(уч-к\.)|(пр-кт\.)|(сад\.)|(остров\.)|(канал\.)|(дор\.)|(км\.)|(городок\.)|(тракт\.)|(гск\.)|(просек\.)|(переезд\.)|(заезд\.)|(парк\.)|(площадь)|(проезд\.)|(туп\.)|(м\.)|(проток\.)|(ст\.)|(вал\.)|(п\.)|(спуск\.)|(пл-ка\.)|(д\.)|(коса\.)|(п\/ст\.)|(пр\.)|(пл\.)|(мкр\.)|(аллея\.)|(кв-л\.)|(ж\/д_будка\.)|(х\.)|(рзд\.)|(тск\.)|(сквер\.)|(стр\.)|(снт\.)|(мост\.)|(метро\.)))*(, )*";"([0-9]*)";"(((д\.)|(ая\.)|(нетр\.)|(д\.)|(а\\я\.)|(а\/я\.))*(([0-9Х]*[-\\\/0-9]*)([\\\/-]([А-Яа-я])*)*))*([^"]*)";"(([0-9]*)([А-Яа-я]*))*"/"\2";"\68";"69";"120";"130"/

I need to convert this database to a different format, I was going to do it using sed and backreferences (\1, \2...), but that's bad luck - sed only supports backreferences from \1 to \9, and I have 130 of them things. Are there any options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2015-12-14
@tooq

Do NOT use regular expressions.
Each tool has its purpose, and regular expressions were a tool to help parse, not the parser itself.
You can use something else instead of SED, where more backreferences are supported. But it's better to rewrite it in pearl or python.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question