I've got a big XML file and I should modify a tag.
Original:
<MyTag>13/19/59/70/68/32'</MyTag>'
What I want with regular expression:
<MyTag>13,19,59,70,68,32</MyTag>
That could be pretty easy if I'd got each time the same quantity of number but I could have 8 number or 5 or 6 or less.
How can I do that in one time?
As already pointed out in the comments, Notepad++'s regexes don't seem to be powerful enough to make that replace. In general, I don't think bare regex replacement isn't powerful enough for this replacement, you could at most get 13/19/59/70/68/32
in a capture group, and perform the /
to ,
replace on that string by other means. That's why maybe I'd consider using another tool you are proficient in (perl, java, whatever) instead.
Using notepad++, I'd go for a normal replace first, to change all occurrences of '</MyTag>'
to </MyTag>
, and then a regex replace with this regular expression: (\\d+)/
. The replace should be \\1,
. Clicking on Replace all should replace all occurrences.
If you wanted to avoid replacing digits separated by /
in other tags, maybe you could use this regular expression <MyTag>(.*)(\\d+)/(.*)</MyTag>
and replace it with <MyTag>\\1\\2,\\3</MyTag>
. This replace will have to be executed N times, so you might be interested in recording a macro or similar if you want to use it.
IT IS POSSIBLE TO DO IN ONE REGEXP.
Search for:
/([0-9]+)('(<){1}/(MyTag>){1}')?
Replace with:
,\1\3\4
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.