C
C
Chvanikoff2011-11-26 21:33:44
Regular Expressions
Chvanikoff, 2011-11-26 21:33:44

How to exclude a subgroup from a group in a regular expression?

There is a line:
<Н1 class="class1 class2">qweqweqwe</Н1>
and there is a regular expression of the form
(<Н1.*?>.*?</Н1>)
how to change it in such a way that as a result, only
<Н1>qweqweqwe</Н1>
That is, throw out what will be “captured” by the first ". *?"

Important extra. a condition due to which I did not break the group into several: in the end there should be only one group - architectural features ...

Answer the question

In order to leave comments, you need to log in

7 answer(s)
M
Meliborn, 2011-11-27
@Meliborn

Regexes and html, html and regexes…
stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454

H
himik, 2011-11-27
@himik

maybe I don’t understand something because it’s too late, but <H1.*?>(.*?)</H1> should be replaced with <H1>$1</H1> is not it?

E
elDraco, 2011-11-28
@elDraco

i think you need this (<H1(?:.*?)>.*?</H1>)

A
Arkady, 2011-11-26
@p0is0n

After all, you get it and are looking for it, how can you exclude it?

E
Evengard, 2011-11-26
@Evengard

Isn't it easier to manually append what you need?

Y
YourChief, 2011-11-26
@YourChief

why don't you split the expression into three different groups and put in the first and third?

G
Genji, 2014-01-05
@Genji

From the regular expression (<Н1).*?(>.*?Н1>) form the result $1$2, if I understood everything correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question