Merging two tags into one in XML
-
Good afternoon! I’ve been racking my head for the second day, I can’t find a solution to the problem
I have this XML big file:<name>offer</name> <id>111</id> <price>111</price> <edizm>м2</edizm> <width>7.5</width> <length>30</length>I need 2 lines
<width>7.5</width> <length>30</length>So that in the end there would be:
<size>7.5x30</size>If you look for one line, he finds it, but he doesn’t want to try two.
SEARCH <width>(?<width>[^"]+)</width>\n\r<length>(?<length>[^"]+)</length> REPLACE <size>$1x$2</size> or <size>/1x/2</size>Please tell me where is my mistake?
-
I might try it this way:
Find:
(?-is)<width>([\d.]+).+>\R\h+<length>([\d.]+).+
Replace:<size>$1x$2</size>
Search mode: Regular expression -
Hello, @дмитрий-прокопьев, @alan-kilborn and All,
Very easy with regexes !
So use the following S/R :
SEARCH
(?-is)^(\h*)<width>(.+)</width>\R\h+<length>(.+)</length>REPLACE
$1<size>$2x$3</size>
Notes :
-
First, in the search regex, the in-line modifiers
(?-is):-
Force the search to be sensitive to case
-
Force the regex engine to consider that the
.regex character represents a standard character ( NOT anyEOLchars )
-
-
Then, the
^syntax refers to the beginning of any line -
Then
(\h*)represents any leadingspacesand/ortabulationsor none, stored as group1 -
Except for the literal parts ( <width>, <width>, <length> and </length> ) two syntaxes are to be considered :
-
(.+)which represents a non-null range of any standard character(s), stored, successively, as groups2and3 -
\R, which represents any kind of line -breaks (\r\nfor Windows files,\nfor Unix files or\rfor MAC files )
-
-
In the replacement regex, three syntaxes are possible :
-
\1<size>\2x\3</size> -
$1<size>$2x$3</size> -
${1}<size>${2}x${3}</size>
-
Best Regards,
guy038
-
-
Thank you very much, it helped a lot!