D
D
darzet2011-08-11 17:16:54
Regular Expressions
darzet, 2011-08-11 17:16:54

Regexp autocorrect

There are a lot of expressions like
< h 1 >I Księga Samuelowa 2< h 1 >
< h 1 >I Księga Samuelowa 3< h 1 >
< h 1 >I Księga Samuelowa 4< h 1 >

Should be replaced with the following
< h 1 >2< / h 1 >
< h 1 >3< / h 1 >
< h 1 >4< / h 1 >

I remember somehow pulled out with \1.

< h 1 >.*?\1< h 1 >
< h 1 >\1< / h 1 >

but it doesn't work like that =(
Help with advice please.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly, 2011-08-11
@taliban

You would indicate what language you use, on js it looks like this:
str.replace(/(<[^>]+>).*?(\d+)<([^>]+)>/g, "$1$2< /$3>")
this is provided that you do not have a closing slash in the source text

I
ivsedm, 2011-08-11
@ivsedm

Hmmm, can't you just remove the unnecessary piece? Like str.replace("I Księga Samuelowa", "")

K
Konstantin, 2011-08-11
@Norraxx

Would you like to write a solution in python? PHP?
Can you suggest a solution in sed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question